Archive for category Prototype

Scrolling to an element when outside of the viewport with prototypejs

Often times you’ll have be playing, say, videos with a list of videos down the page. If the list gets too long the video player becomes out of sight as the user scrolls down. This can be a big confuser to users: they click on a link to see a video and they don’t see anything happen because the video player is out of sight. Here’s what you can do: scroll to the video player if it is out of sight like so:

if ($("videoplayer").viewportOffset()[1] < 0) {
 Effect.ScrollTo('videoplayer', {duration: 0.2});
}

Requires both prototype and effects.js in scriptaculous.

  • Share/Bookmark

No Comments

Stylize the last element in prototype

Here is an example of removing the last border in a list of elements.

Event.observe(window, "load", function() {
    $$(".homepageContainer .upcomingEvents").last().setStyle({
        border: 0
    });
}); Read the rest of this entry »
  • Share/Bookmark

No Comments

Truncating Text with JavaScript

Since Alex posted an article on truncating text with Prototype, I thought I would write an article on truncating text without the help of a JavaScript framework. Read the rest of this entry »

  • Share/Bookmark

3 Comments

How to Truncate in Prototype

This is to truncate multiple items in the javascript library Prototype. If it has the class=”truncate” it will be truncated! Read the rest of this entry »

  • Share/Bookmark

2 Comments