Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Image Drag bookmarklet

I got a good response to yesterday’s call for help on finding an HTML element’s co-ordinates on a page. I ended up using PPK’s findPos functions which seemed to do the trick just fine.

Here’s the result:

Image Drag (bookmarklet, drag on to your links bar).

Image Drag makes every image on a page “draggable”, using youngpup’s DOM-Drag library. It works by “cloning” each image on the page and making the clone an absolutely positioned, draggable element then changing the original image to a transparent pixel of the correct width and height. I wrote it because I wanted my girlfriend to be able to play with GothMaker in Phoenix instead of IE, but it works for other pages too. There is a weird bug which affects any pages that use absolute positioning (such as this one)—I think it’s a bug in DOM-Drag rather than a problem with findPos but I’m not entirely sure what’s causing it.

The bookmarklet works fine in Phoenix (on both Linux and Windows) but doesn’t work in IE. I’m not too bothered about this—with IE6 nearing it’s second birthday if you are still using it you should seriously considering upgrading to something a bit more up to date anyway.

Since most of the sites linked to from this one use absolute positioning, here are a few which the bookmarklet works well on that are fun to mess around with:

Incidentally, although it’s only meant as a fun distraction, having played with it a bit it looks like it could be quite useful as a tool for web site design tweaks such as seeing if the page would look better with images moved around a bit.

Update: It turns out the bookmarklet only works for pages that aren’t being served with an XHTML doctype. Curious.

This is Image Drag bookmarklet by Simon Willison, posted on 8th February 2003.

View blog reactions

Next: Hashing client-side data

Previous: Help needed

13 comments

  1. For similar fun in ie, you could try this

    paul hammond - 8th February 2003 17:22 - #

  2. Fun bookmarklet, Simon. FYI: It also works in Chimera but not in Safari.

    Joshua Kaufman - 8th February 2003 19:43 - #

  3. There's a problem with that DOM-drag library, in that it doesn't support scrolling... you start to drag something, then use the scroll wheel without thinking, and end up leaving the image of the screen, but still responding to the drag of the mouse, to be lost for ever... well, almost. And is it just me, or can no one else see your post for yesterday? It just ain't there.

    Andrew - 8th February 2003 20:34 - #

  4. cool stuff :) - yeah, i can't yesterday's entry either.

    MyDimension - 8th February 2003 20:50 - #

  5. Wonderful bookmarklet! Incredibly cool. It does work in Phoenix, but unfortunately not for XHTML pages served as "application/xhtml+xml", e.g.: http://www.bertilow.com/persone/index.php But it's a know fact that such pages don't work well with Javascript in Mozilla/Phoenix.

    Bertilo - 8th February 2003 22:30 - #

  6. Just noticed a little thing about your Image Drag bookmarklet... I don't think it works in framesets.

    Andrew - 8th February 2003 22:37 - #

  7. Nope it won't work in framesets because it won't be able to find the document object for the individual frames. I'm trying to figure out what happened to yesterday's entries - they're in the database but they've vanished from the front page. Very odd.

    Simon Willison - 8th February 2003 23:33 - #

  8. Very cool. works in galeon too.

    Joe - 9th February 2003 01:18 - #

  9. I've tracked down the problem - the bookmarklet breaks (i.e all images "warp" to the top left) in anything served with an XHTML Strict doctype. Anyone know if there's a site somewhere that documents the differences between javascript behaviour in quirks and strict mode?

    Natalie Downe - 9th February 2003 16:50 - #

  10. The problem with XHTML is in the following code in http://simon.incutio.com/js/imagedrag.js : newimg.style.width = width; newimg.style.height = height; newimg.style.top = top; newimg.style.left = left; In standards mode, CSS lengths must have a unit, so those lines should look like: newimg.style.top = top + "px"; See http://www.mozilla.org/docs/web-developer/quirks/q uirklist.html for fairly exhaustive documentation on the differences between the modes in Mozilla.

    Boris - 11th February 2003 22:57 - #

  11. That worked a treat! Thanks - I've fixed the bookmarklet file on my server now so anyone who's already installed it should find it suddenly miraculously works on "strict mode" sites.

    Simon Willison - 12th February 2003 00:59 - #

  12. mozecie pisać po polsku???????????????????????????????????????????? ??????????????/

    kola - 9th January 2004 19:49 - #

  13. ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ???????????????????????????????

    kola - 9th January 2004 19:51 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/02/08/imageDragBookmarklet

A django site