Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // зум фотки на странице детального просмотра
- $('.zoomer').mouseenter(function(e) {
- var $this = $(this), $img = $(this).children('img'),
- containerHeight = $this.outerHeight(), containerWidth = $this.outerWidth();
- // ratio
- var kX, kY;
- // fix container size
- $this.css({
- height: containerHeight+'px',
- width: containerWidth+'px',
- backgroundImage: 'url('+$img.attr("src")+')'
- });
- $img.hide();
- // prepare image
- $("<img/>").attr("src", $img.attr("src")).load(function() {
- kX = (this.width-containerWidth)/containerWidth;
- kY = (this.height-containerHeight)/containerHeight;
- });
- // catch movement
- $this.mousemove(function(e) {
- var posX = e.pageX-$(this).offset().left,
- posY = e.pageY-$(this).offset().top;
- var bgX = -1*posX*kX, bgY = -1*posY*kY;
- $this.css('background-position', bgX+'px '+bgY+'px');
- });
- $this.mouseleave(function() {
- $this.css('background-image', 'none');
- $img.show();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment