How can I customise jquery loupe to have a circular lens?

2.6k views Asked by At

I would appreciate the thoughts of any javascript / css ninjas on how I can customise:

https://github.com/jdbartlett/loupe/blob/master/jquery.loupe.js

To have a circular zoom area instead of rectangular one? There is an option to set a css class for the loupe.

Please note that this is a question about the library linked above. I have already googled for other libraries. I want to keep the js as small as possible.

2

There are 2 answers

0
codecowboy On BEST ANSWER

From the developer of loupe.js:

you may want to look at chris iufer's loupe, which is only a bit bigger than mine and includes a few samples that use css3 to achieve a round loupe:

http://chrisiufer.com/loupe/sample.html

whereas mine uses an absolutely positioned image within a div, his uses background-image on the div and background-position to move the image, so css3 border-radius works.

5
Fred Bergman On

I guess the easiest way to do this is to use CSS3 border-radius, which is supported by the modern versions of all web-browsers (no IE lower than version 9).

If you have this in your javascript

$('selector').loupe({
    width: 150, // width of magnifier
    height: 150, // height of magnifier
    loupe: 'loupe' // css class for magnifier
});

Just put this in your css:

.loupe {
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
border-radius: 150px;
}

... and all old versions of IE will just show a square, which is maybe OK in your case?