Realization of magnifying glass effect based on jquery _jquery

Source: Internet
Author: User

Major shopping malls detailed page product picture effects show, the mouse over small figure shows the figure, the mouse over the figure show large picture display, jquery magnifying glass effect picture similar picture magnifying glass display, improve user experience design, jquery picture Magnifier effect is a typical picture effects show.

The effect chart is as follows:

Picture big box Initial style:

 <div class= "Goods-imginfo-bimg-box" style= Background-image:url (http://www.od.my/images/201507/thumb_img/142_ Thumb_p_1435792664520.jpg); position:relative; " ></div>

Add Enlarge area box and enlarge effect box

picbox=$ ('. Goods-imginfo-bimg-box ');
Picbox.css (' position ', ' relative ');
Picbox.append (' <div class= ' Mag-sbox "></div>");
Picbox.append (' <div class= ' Mag-box "></div>");

Add a style sheet

$ ("Head"). Append (' <link rel= "stylesheet" type= "Text/css" href= "Themes/od/css/mag.css" > ");

Style

@CHARSET "utf-"; . mag-sbox{position:absolute;border:px solid #fff; Background-color:rgba (,,,.);
 Cursor:crosshair;z-index:;d Isplay:none;}
 . Mag-box{position:absolute;left:%;top:;margin-left:px;border:px solid #ccc; width:%;height:%;
 Background-size:cover;background-color: #fff; Z-index:;d isplay:none; JS/* Magnifier effect * Do not change the previous code * Add Magnifier effect * to Goods-imginfo-bimg-box; */$ ("Head"). Append (' <link rel= "stylesheet"
 Type= "Text/css" href= "Themes/od/css/mag.css" ">");
 picbox=$ ('. Goods-imginfo-bimg-box ');
 Picbox.css (' position ', ' relative ');
 Picbox.append (' <div class= ' Mag-sbox "></div>");
 Picbox.append (' <div class= ' Mag-box "></div>");
 msbox=$ ('. Mag-sbox ');
 mbox=$ ('. Mag-box '); bs=;
 Multiple Msbox.css ({width:picBox.width ()/+ ' px ', height:picBox.height ()/+ ' px '});
 Mbox.css ({' backgroundsize ': bs*+ '% '}); Picbox.mousemove (function (e) {mbox.css (' BackgroundImage ', $ (this). CSS (' backgroundimage ');//give large picture background if (' Display ')!= ' block ' {//mouse put up, the scope box and effectBox Msbox.show ();
  } if (Mbox.css (' Display ')!= ' block ') {mbox.show ();
  /* Mouse Mobile/Xleft=e.pagex-picbox.offset () left-msbox.width ()/;
  if (xleft<) {xleft=;
  }else if (Xleft>picbox.width ()-msbox.width ()) {xleft=picbox.width ()-msbox.width ();
  } xtop=e.pagey-picbox.offset (). Top-msbox.height ()/;
  if (xtop<) {xtop=;
  }else if (Xtop>picbox.height ()-msbox.height ()) {xtop=picbox.height ()-msbox.height ();
  } msbox.css ({' Left ': xleft+ ' px ', ' top ': xtop+ ' px '});
 Mbox.css ({' backgroundposition ':-bs*xleft+ ' px ' +-bs*xtop+ ' px '});
 });
  Picbox.mouseout (function () {msbox.hide ();
 Mbox.hide (); });

The above code is based on jquery to achieve Magnifier effect, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.