• Menu
  • Lycoris
  • Category
    • Animation
    • Nature
    • People
    • Technology
    • Vogue
    • Other
  • Tools
    • CSS
    • jQuery
    • Cookies
    • Wicked
  • Menu
    • CSS
    • jQuery
    • Cookies
    • Wicked
  • Sub Menu
    • CSS
    • jQuery
    • Cookies
    • Wicked

Top Free IT

Share free template blogger

  • Home
  • Contact
  • Sitemap
  • Static Page
Menu
CSS How to jQuery Magnifying Glass How to Add jQuery i CSS3 Magnifying Glass

How to Add jQuery i CSS3 Magnifying Glass

Idea came by surfing web and saw on some site how they made this awesome effect. There is similar effect on my blog, maybe better, but this one isn't bad at all on contrary, you will see and you will lke it 100%. Take a look at the site I mentioned above, you may find some solution how to implement this hack. You have to know CSS, HTML i jQuery for this. Here is one way  - Zoom Effect 1  ,read it, it's cool. The only diference is in codes and style. This one is a little harder for beginners.
 Magnifying Glass

  • Zoom Effect To Your Blog Images On Mouse Hover
  • LIVE DEMO Result

 HTML
 <img class="magniflier" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8vgSzzMMt-SmXt20uu4jzn18vlAnu9VMJwHhPi9ciAGMiPUNFa3WOhuVmmcNSVXFFue7HhpJVsbyu44iUCehGxl2-qqltuomJY2qZz361GSAEFAgKASBxgO7YqzsB4A_Cdaff4HVeOU4/s1600/iphone-5-thumb%5B1%5D.jpg" width="460"/>

Replace "image.jpg" with your image URL

CSS
.glass {
  width: 170px;
  height: 170px;
  position: absolute;
  border-radius: 50%;
  cursor: crosshair;
  /* Multiple box shadows to achieve the glass effect */
  box-shadow:
    0 0 0 7px rgba(255, 255, 255, 0.85),
    0 0 7px 7px rgba(0, 0, 0, 0.25),
    inset 0 0 40px 2px rgba(0, 0, 0, 0.25);
    display: none;
}

CSS gives you style and make Magnify


jQuery
$(function() {
  var native_width = 0;

  var native_height = 0;
  var mouse = {x: 0, y: 0};
  var magnify;
  var cur_img;
  var ui = {
    magniflier: $('.magniflier')
  };
  // Connecting to the magnifying glass
  if (ui.magniflier.length) {
    var div = document.createElement('div');
    div.setAttribute('class', 'glass');
    ui.glass = $(div);
    $('body').append(div);
  }
  // All the magnifying will happen on "mousemove"
  var mouseMove = function(e) {
    var $el = $(this);
    // Container offset relative to document
    var magnify_offset = cur_img.offset();
    // Mouse position relative to container
    // pageX/pageY - container's offsetLeft/offetTop
    mouse.x = e.pageX - magnify_offset.left;
    mouse.y = e.pageY - magnify_offset.top;
 
    // The Magnifying glass should only show up when the mouse is inside
    // It is important to note that attaching mouseout and then hiding
    // the glass wont work cuz mouse will never be out due to the glass
    // being inside the parent and having a higher z-index (positioned above)
    if (
      mouse.x < cur_img.width() &&
      mouse.y < cur_img.height() &&
      mouse.x > 0 &&
      mouse.y > 0
      ) {
      magnify(e);
    }
    else {
      ui.glass.fadeOut(100);
    }
    return;
  };
  var magnify = function(e) {
    // The background position of div.glass will be
    // changed according to the position
    // of the mouse over the img.magniflier
    //
    // So we will get the ratio of the pixel
    // under the mouse with respect
    // to the image and use that to position the
    // large image inside the magnifying glass
    var rx = Math.round(mouse.x/cur_img.width()*native_width - ui.glass.width()/2)*-1;
    var ry = Math.round(mouse.y/cur_img.height()*native_height - ui.glass.height()/2)*-1;
    var bg_pos = rx + "px " + ry + "px";
 
    // Calculate pos for magnifying glass
    //
    // Easy Logic: Deduct half of width/height
    // from mouse pos.
    // var glass_left = mouse.x - ui.glass.width() / 2;
    // var glass_top  = mouse.y - ui.glass.height() / 2;
    var glass_left = e.pageX - ui.glass.width() / 2;
    var glass_top  = e.pageY - ui.glass.height() / 2;
    //console.log(glass_left, glass_top, bg_pos)
    // Now, if you hover on the image, you should
    // see the magnifying glass in action
    ui.glass.css({
      left: glass_left,
      top: glass_top,
      backgroundPosition: bg_pos
    });
    return;
  };
  $('.magniflier').on('mousemove', function() {
    ui.glass.fadeIn(100);
 
    cur_img = $(this);
    var large_img_loaded = cur_img.data('large-img-loaded');
    var src = cur_img.data('large') || cur_img.attr('src');
    // Set large-img-loaded to true
    // cur_img.data('large-img-loaded', true)
    if (src) {
      ui.glass.css({
        'background-image': 'url(' + src + ')',
        'background-repeat': 'no-repeat'
      });
    }
    // When the user hovers on the image, the script will first calculate
    // the native dimensions if they don't exist. Only after the native dimensions
    // are available, the script will show the zoomed version.
    //if(!native_width && !native_height) {
      if (!cur_img.data('native_width')) {
        // This will create a new image object with the same image as that in .small
        // We cannot directly get the dimensions from .small because of the
        // width specified to 200px in the html. To get the actual dimensions we have
        // created this image object.
        var image_object = new Image();
        image_object.onload = function() {
          // This code is wrapped in the .load function which is important.
          // width and height of the object would return 0 if accessed before
          // the image gets loaded.
          native_width = image_object.width;
          native_height = image_object.height;
          cur_img.data('native_width', native_width);
          cur_img.data('native_height', native_height);
          //console.log(native_width, native_height);
          mouseMove.apply(this, arguments);
          ui.glass.on('mousemove', mouseMove);
        };


        image_object.src = src;
       

        return;
      } else {
        native_width = cur_img.data('native_width');
        native_height = cur_img.data('native_height');
      }
    //}
    //console.log(native_width, native_height);
    mouseMove.apply(this, arguments);
    ui.glass.on('mousemove', mouseMove);
  });
  ui.glass.on('mouseout', function() {
    ui.glass.off('mousemove', mouseMove);
  });
});

Final Words. 
If you want to get back your pictures to normal, without magnifying, simply switch   <img class="magniflier"  to normal code which was before you added this one.

That's it, if you can handle, please, lieve a comment, that would be so valuable, if not, we will try to find some solution, jQuery and CSS are hard to manage but nothing is impossible. Happy Blogging dear friends !


Unknown
Add Comment
CSS, How to, jQuery, Magnifying Glass
Wednesday, October 7, 2015
  • Share
  • Share

Related Posts

  • How to Create Full Screen Preloading Effect LIVE DEMODOWNLOADIn this tutorial, We will learn how to create full screen simple,clean preloading
  • Jquery and Css Vertical Drop Down MenuGreat Widget because it does not takes a lot space even makes you more valuable space and still is
  • How to Add Jumbo Social Share Bar with Counters in BloggerAre you looking to add a Jumbo social share bar in Blogger? Why it is called a Jumbo Social Bar? Wh
  • How To Add Related Posts Widget To Blogger with Thumbnails Here is a wonderful hack for displaying related posts beneath each of your blog posts, along with t
  • How to Add jQuery "Back To The Top and Go to the Bottom" ArrowsDEMO  Not only It looks beautiful, but is very useful for bloggers, blogs and websites. And al
  • How to Add Black Navigation Menu Bar Widget For BloggerBlack navigation menu bar widget for blogger. Black is a very professional color and this is the re

Newer Older Home
Lycoris Responsive Blogger Template

Lycoris Responsive Blogger Template

Mauris mattis auctor cursus. Phasellus tellus tellus, imperd…

Most Awesome Breathtaking Places

Most Awesome Breathtaking Places

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sat…

Overall of Fashion Week

Overall of Fashion Week

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sat…

Awesome Fashion Trend in For Winter

Awesome Fashion Trend in For Winter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sat…

7 Ways To Travel Like a Pro

7 Ways To Travel Like a Pro

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sat…

<12345>

Weekly Posts

  • thumbnails
    Viralisme
  • thumbnails
    How to Create Rounded Images with CSS
  • thumbnails
    Viral Pro
  • thumbnails
    Strap Blog
  • thumbnails
    eLearn
  • thumbnails
    Gravity V3 Responsive Blogger Template

Label

1 Column 2 Column 2016 2017 3rdball 3rdbell Acacia Active Mag Ad Mag Adelle Adello Admiral Tumblr Theme Ageka Simple Agista Ajustmag Alice Allure Amadeus aMag Amalie Amazine AMP Template AnankeMag Anime Anime Clean AnimeBatch AnimeMagzs AnimePacker Animeplus AnimeTango Arden Argent Arlinadesign Asteroid Astonish Author Widget Authority Auto Razz Auto Read More Autumn Avocet AwesomeOne Axact Back To The Top Barbar Base Beauteous 2016 Beauty BeautyTemplates Beehive Best Mag Better Mag BizDesk BizGlobe Black Black Cover Blacken BLagioke Blogable Blogari Blogger Blogger Magazine Blogger Template Blogger Templates Blogger Widgets Bloggertheme9 Blogghiamo Blogging Blogish Blogius Blogmag BlogrCart BlogrCart Closet v2 BlogrCart Mukabuku Blogrcart One BlogrCart SHOWCASED BlogrCart White2 BlogrShop Blogstar Blogus Blue Blue APK BlueTheme Blush Bmag BoldNews Bolina Brosense Brown Brownie Bthemez Bulan Busby Bushwick Business Businis Button Buttons Calypso Canvas Clock CarsPortal Cartoons CarZilla CB Blog Foto CelebVision ChicMag Chitoge Attack Claire Clothing CocoMag Colorindo Coming soon Conversion Cool Mag Coolbaby Cooperate Coral Drive Corner Mag Cosparell Count Me Couture Creative CreativePen Crystal CSS CSS3 CTR Booster Daily Health DaisyChain Daksh Dark Color DarkMag Date A Live Davis Dearpins Decent Deep Blog Defersite Delivery Lite Demo Page DeNews Design and CSS DesignIdea DesignPress Detube Deverclean Devil Survivor Devote Devotion Grid Discover Djogzs Dollar Sense Domag Download Buttons DreamLine Drop Down Menu Dropen Duena Duos Mag Dzine Easy Blog Easy Mag EasyMag Edogawa Education EducationPro Effective eLearn Elegantes Eleganto eNewspaper Estelle Evo Magz Exmanga ExpressNews Extra News Fabish Facebook Fag Mag Familia Fan Base Fanbase v2.2 Fancy Fanstrap Anime Fantasy Fasel News Fashion Fashion Blogger Template Fashionistas Fashionly Fast 2 Fast Edition Fast Gear fastnews Feedly Felice Fenomen Figaro Film Reviews Final Fantasy Fitness Diva Flashback FlatMag Flatness Flavio Flavio Simple Flexmag Flytemplate Food Food Blog Foodlicious FootballZone Foto Fotografity Foundia Free Blogger Template Free Premium Fresh Blog Fresh View Frontier Fusion G Vusion Gallery GameDaily GameFusion GameMag GameMaster Gameport Gamer Games GamesExpo GamesNet GamesPad GamingCenter Gear World GeoWall GirdBook Gladiolus Minimal Glam Up Glamour Glooger Gommero Gordon Gossip Gracious Gray GreatMag Green Green APK Pro GreenMag Grey Grid Template Gridisme Gumi Vocaloid Gym Happenings HaralampiLux Harmonia Hatsune Miku Headlines Health Health/Fitness HealthDaily HealthLab HealthPro HealthyLiving HeradinoMag HestiaMag HighEnd Hitamz Holomatic Honey HorseMag HostingBlog Hotmag How to HTML HugeMag iBeats Image Image Gallery Immersed iMoechan Impreza Indzign Ingrid Instaset Instinct Intent Invert Invert Grid Invision Iori Kyun iPrime iPro Irsah Ivanesia Ivero Iwata JalanTikus Jax Lite Jaximus Jenny Johansen JosePhine JoyFul Fashion JPStation jQuery JQuery Widgets Jugas Jumper Jupiter Kalimaz Kalon KitKat Klarity Koenda Kompi Landing Page Kompi Males Kontify Krakatau Lite Kuro Simple Kyoukai no kanata Lady Finger Lagicapek Landing Page Language Attribute Ledera Lemy LepontoMag Life-Fashion LifeBlog Lifestyle Lifestyle Magazine Limelight Livinia LocalNews Loveria LunaMag Lux News Mag Zilla Magazine Magazine Template Magcro Parallax Magento Magnifique Magnifying Glass MagOne MagtiMate MagTime MagWeb Magzima Marble Mashable Maskolis Masterpiece MaterialZine MaxaZine MaxTemplate Maya McKinley Mdcsite MDFostrap Meed Mega mag Mega Shop Mega Social Menowo MetroMag Micro Mag MicrownSoft Grid Milano Mini-T Minima Minima Colored Minimal Minimalist Mistery MNMLIS MobileZone Modern ModernMag Monal Montric Motive Mag Moveone Movie MovieSpot msdesignbd mSora Mugi Mularonis Multimedia MultiPurpose Blogger Template My Mag MyRestaurant Mystery N Light Nami Press Nanopress Navigation Menu Neda NeedMag Neo Mag NEOMAGz Netia New Minima Colored NewBloggerThemes NewMag NewNews NEWS News 52 News24 NewsBoard NewsCenter NewsGrand Newsly Newspaper NewsPark NewsPro NewsTube NewsZoom Nimbus Nisekoi Novelo Nubie Banget Ocean Mag Odd Themes Old Themes Older Themes Olive Olivia One Page OneStream OnlineMagazine OpenNews Oracle Orange Ore no Imouto Oreki Houtarou Origins Otaku News Ovation Overload Padhang Pago Pakdhe Johny Palki Palki 2 Palki Grid Palki Ultimate Particular Responsive PBT PBThemez Perish Personal Personal Blog Personal template Photo Photographer Blogger Template Photography Phrozen2 Picshots Picture Pink Pinterest Pointer Portfolio Power Game Powered by Blogger Precious Lite Preloading Effect Premium Premium Themes PremiumBloggerTemplates PressMania Pro Templates Lab Probama ProMag ProNews ProNewspaper Publisher Purple Raintemplates Raintimes Raspberry Rastolinos Read More Readily Reading Red ReDesign Related Posts Responsive ReStyle Revelio Rezero Chan Risa RokoPhoto Rosemary Scoop Scratch SeeNews Sense Seo Beast Blogger Templates Seo Boss seobloggertemplates Seofast Setiva Shine Shingeki No Kyojin Shiroi Shop Template Silver Simplart Simple Fast Simple Sense SimpleBuzz Simplesanget Simplest Simplex Simplex Audio Simplify Simply Mag Sincup Singl Sleekify Slider Smart Blog Smart News SmartBlog Smartseo SNews Snowseo Social Icons Social Share Buttons SocialMediaMarketing Socio SoftWind Solar Solon Soone Soonex Sora Sora Book Sora Buzz Sora Films Sora Games Sora Mag Sora Travels Sparkle Sparkling Splendid Splendor 2 SpotCommerce Spraymag Square StagoMag Strength Studio Stylish Subscribe to Subscription Box Sugar SunMag Sure APK SweeTravel Swift Takis Team Blog Tech Tech Life Tech Mag Tech World TechBlog TechGo TechJournal TechLand Technext Technology TechPro TechTrend TechUp TechZine Template TemplateClue Templateify Templateism Templatesyard Templatetrackers Templatezy Templatium Templatoid The Blog Theme The Dens The Reviewer TheAcademy TheBloopers TheCars Theme Theme Mag Themeforest Themeindie Themeswear Themexpose TheMusic TheNews TheSmart TimesDay Toniq Tooltip TopGames Torrentism Toujours TP Blue Mag Travel Travel Blog Travel Hub TravelHub Treasury Trendmag Trendy Divaa Tribes Tribute TriVusion Trophy Tubies Tumblr Ultimate Tech Under Construction UniEdu Uong Jowo UpMag UpStream Usagilabs Vacations Value Veethemes Verda Vidal Video VideoPro VideoShow Vienna Vienna Lite 2 Vienna Lite 3 Vikka VipMag Viral Mag Viral Pro Viral Ta ViralNews Vogue 2016 Voux Wallbar Warm Mag way2themes Weblogtemplates Wedding White Widget Widgets Wizzblue WorldGamer WpHealth WPNewsPaper Writer Writer Evolution X-Man XPress News Yellow YesNews Yo MAG Yo Templates YouMusic YouNews Youtube Responsive Blogger Template Zen Mag Zinnias Lite Zippo Zipson Zoom Effect

Recent Post

  • All topics simplify 2 premium for blogger
  • Gravity V3 Responsive Blogger Template
  • Moslar
  • Vox - Responsive
  • Axorys Blogger Template
  • TdbSimple2
  • Viralisme
  • Simple Template
  • AMPNews
  • Digizena

Contact

Name

Email *

Message *

  • Trang chủ

copyright © 2017 Top Free IT All Right Reserved . Created by Idntheme . Powered by Blogger