2016-11-09 16 views
1

ホバリングメイン画像では、ズーム画像に指定された幅と高さなどのプロパティが表示されます。コードは機能していますが、ホバーのメイン画像のズーム画像の問題です。ホバリングメイン画像では、ズーム画像に幅が適用されていません。下にある添付画像を参照してください。

/* This is my script. I have used this for my code in this, marksize indicates id="mark" in my html main image and zoomImg indicates width and height for on hover the main image. */ 
 

 
$(function(){ \t 
 
    $("#show").simpleZoom({ 
 
    zoomBox : "#zoom", 
 
    markSize : \[120, 169\], 
 
    zoomSize : \[800, 400\], 
 
    zoomImg : \[480, 677\] 
 
    }); 
 
}); 
 
      
 
(function($){ 
 
      \t $.fn.simpleZoom = function(options){ 
 
      \t \t var defs = { 
 
            markSize : \[200, 100\], \t \t 
 
      \t \t \t zoomSize : \[400, 400\], \t \t 
 
      \t \t \t zoomImg : \[800, 800\] \t \t \t 
 
      \t \t }; 
 
      \t \t var opt = $.fn.extend({}, defs, options); 
 
      \t \t return this.each(function(){ 
 
      \t \t \t var markBox = $(this); 
 
      \t \t \t var zoomBox = $(opt.zoomBox); 
 
      \t \t \t var zoom_img = $(opt.zoomBox).find("img"); 
 
      \t \t \t var markBoxSize = \[markBox.width(), markBox.height(), markBox.offset().left, markBox.offset().top\]; 
 
      \t \t \t var markSize = opt.markSize; 
 
      \t \t \t var zoomSize = opt.zoomSize; 
 
      \t \t \t var zoomImg = opt.zoomImg; 
 
      \t \t \t var mark_ele = "<i id='mark'></i>"; 
 
      \t \t \t var mark_css = {position:"absolute", top:0, left:0, width:markSize\[0\]+"px", height:markSize\[1\]+"px", backgroundColor:"#000", opacity:.5, filter:"alpha(opacity=50)", display:"none", cursor:"crosshair"}; 
 
      \t \t \t 
 
      \t \t \t var show_w = markBoxSize\[0\]-markSize\[0\]; 
 
      \t \t \t var show_h = markBoxSize\[1\]-markSize\[1\]; 
 
      
 
      \t \t \t //created mark element and add cascading style sheets 
 
      \t \t \t zoomBox.css({width:zoomSize\[0\]+"px", height:zoomSize\[1\]+"px"}); 
 
      \t \t \t markBox.append(mark_ele); 
 
      \t \t \t $("#mark").css(mark_css); 
 
      
 
      \t \t \t markBox.mouseover(function(){ 
 
      \t \t \t \t $("#mark").show(); 
 
      \t \t \t \t zoomBox.show(); 
 
      \t \t \t }).mouseout(function(){ 
 
      \t \t \t \t $("#mark").hide(); 
 
      \t \t \t \t zoomBox.hide(); 
 
      \t \t \t }).mousemove(function(e){ 
 
      \t \t \t \t var l = e.pageX-markBoxSize\[2\]-(markSize\[0\]/2); 
 
      \t \t \t \t var t = e.pageY-markBoxSize\[3\]-(markSize\[1\]/2); 
 
      \t \t \t \t if(l < 0){ 
 
      \t \t \t \t \t l = 0; 
 
      \t \t \t \t }else if(l > show_w){ 
 
      \t \t \t \t \t l = show_w; 
 
      \t \t \t \t } 
 
      \t \t \t \t if(t < 0){ 
 
      \t \t \t \t \t t = 0; 
 
      \t \t \t \t }else if(t > show_h){ 
 
      \t \t \t \t \t t = show_h; 
 
      \t \t \t \t } 
 
      \t \t \t \t $("#mark").css({left:l+"px", top:t+"px"}); \t \t \t \t 
 
      \t \t \t \t var z_x = -(l/show_w)*(zoomImg\[0\]-zoomSize\[0\]); 
 
      \t \t \t \t var z_y = -(t/show_h)*(zoomImg\[1\]-zoomSize\[1\]); 
 
      \t \t \t \t zoom_img.css({left:z_x+"px", top:z_y+"px"}); 
 
      \t \t \t }); 
 
      \t \t }); 
 
      \t } 
 
})(jQuery);
#show { 
 
    width: 100%; 
 
    height: 400px; 
 
    overflow: hidden; 
 
    position: relative; 
 
    left: 0; 
 
} 
 
#show_mark { 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 200px; 
 
    height: 100px; 
 
    background-color: #000; 
 
    opacity: .5; 
 
    filter: alpha(opacity=50); 
 
    cursor: crosshair; 
 
    border: 1px solid #999; 
 
    display: none; 
 
} 
 
#zoom { 
 
    position: absolute; 
 
    left: 250px; 
 
    top: 0; 
 
    z-index: 99; 
 
    /*width: 400px;*/ 
 
    height: 400px; 
 
    display: none; 
 
    overflow: hidden; 
 
    border: 1px solid #eee; 
 
} 
 
#zoom img { 
 
    position: absolute; 
 
    left: 0; 
 
    top: 0; 
 
} 
 
#show_pic{ 
 
    display: block !important; 
 
    width: 60% !important; 
 
    height: 400px !important; 
 
    margin: 0 0 0 21%; 
 
}
<div class="main"> 
 
    <div id="show"> 
 
    <img src="<?php echo 'data:image;base64,'.$productimage; ?>" id="show_pic" /> 
 
    </div> 
 
    <div id="zoom"> 
 
    <img src="<?php echo 'data:image;base64,'.$productimage; ?>"/> 
 
    </div> 
 
</div> 
 
     

示す上記は私の画像です。すぐに私を参照して助けてください。

答えて

3
Instead of the above code i have done with this and it's working fine. 

HTMLコード

<div class="bzoom_wrap"> 
     <ul id="bzoom"> 
      <li> 
       <img class="bzoom_thumb_image" src="saree.jpeg" /> 
       <img class="bzoom_big_image" src="saree.jpeg"/> 
      </li> 
      <li> 
       <img class="bzoom_thumb_image" src="saree1.jpeg"/> 
       <img class="bzoom_big_image" src="saree1.jpeg"/> 
      </li> 
      <li> 
       <img class="bzoom_thumb_image" src="saree2.jpeg"/> 
       <img class="bzoom_big_image" src="saree2.jpeg"/> 
      </li> 
     </ul> 
    </div> 

スクリプト私が使用している

<script type="text/javascript"> 
     $("#bzoom").zoom({ 
      zoom_area_width: 400, 
      autoplay_interval: 3000, 
      small_thumbs: 3, 
      autoplay: false 
     }); 
    </script> 

    <script> 

     (function ($) { 
      $.fn.zoom = function (options) { 

       var _option = { 
        align: "left", 
        thumb_image_width: 380, 
        thumb_image_height: 400, 
        source_image_width: 450, 
        source_image_height: 450, 
        zoom_area_width: 400, 
        zoom_area_height: "justify", 
        zoom_area_distance: 10, 
        zoom_easing: true, 
        click_to_zoom: false, 
        zoom_element: "auto", 
        show_descriptions: true, 
        description_location: "bottom", 
        description_opacity: 0.7, 
        small_thumbs: 3, 
        smallthumb_inactive_opacity: 1, 
        smallthumb_hide_single: true, 
        smallthumb_select_on_hover: false, 
        smallthumbs_position: "bottom", 
        show_icon: true, 
        hide_cursor: false, 
        //   speed: 600,     
        autoplay: true, 
        //   autoplay_interval: 6000,  
        keyboard: true, 
        right_to_left: false, 
       } 

       if (options) { 
        $.extend(_option, options); 
       } 

       var $ul = $(this); 
       if ($ul.is("ul") && $ul.children("li").length && $ul.find(".bzoom_big_image").length) { 

        $ul.addClass('bzoom clearfix').show(); 
        var $li = $ul.children("li").addClass("bzoom_thumb"), 
          li_len = $li.length, 
          autoplay = _option.autoplay; 
        $li.first().addClass("bzoom_thumb_active").show(); 
        if (li_len < 2) { 
         autoplay = false; 
        } 

        $ul.find(".bzoom_thumb_image").css({width: _option.thumb_image_width, height: _option.thumb_image_height}).show(); 

        var scalex = _option.thumb_image_width/_option.source_image_width, 
          scaley = _option.thumb_image_height/_option.source_image_height, 
          scxy = _option.thumb_image_width/_option.thumb_image_height; 

        var $bzoom_magnifier, $bzoom_magnifier_img, $bzoom_zoom_area, $bzoom_zoom_img; 


        if (!$(".bzoom_magnifier").length) { 
         $bzoom_magnifier = $('<li class="bzoom_magnifier"><div class=""><img src="" /></div></li>'); 
         $bzoom_magnifier_img = $bzoom_magnifier.find('img'); 

         $ul.append($bzoom_magnifier); 

         $bzoom_magnifier.css({top: top, left: left}); 
         $bzoom_magnifier_img.attr('src', $ul.find('.bzoom_thumb_active .bzoom_thumb_image').attr('src')).css({width: _option.thumb_image_width, height: _option.thumb_image_height}); 
         $bzoom_magnifier.find('div').css({width: _option.thumb_image_width * scalex, height: _option.thumb_image_height * scaley}); 
        } 


        if (!$('.bzoom_zoom_area').length) { 
         $bzoom_zoom_area = $('<li class="bzoom_zoom_area"><div><img class="bzoom_zoom_img" /></div></li>'); 
         $bzoom_zoom_img = $bzoom_zoom_area.find('.bzoom_zoom_img'); 
         var top = 0, 
           left = 0; 

         $ul.append($bzoom_zoom_area); 

         if (_option.align == "left") { 
          top = 0; 
          left = 0 + _option.thumb_image_width + _option.zoom_area_distance; 
         } 

         $bzoom_zoom_area.css({top: top, left: left}); 
         $bzoom_zoom_img.css({width: _option.source_image_width, height: _option.source_image_height}); 
        } 

        var autoPlay = { 
         autotime: null, 
         isplay: autoplay, 
         start: function() { 
          if (this.isplay && !this.autotime) { 
           this.autotime = setInterval(function() { 
            var index = $ul.find('.bzoom_thumb_active').index(); 
            changeLi((index + 1) % _option.small_thumbs); 
           }, _option.autoplay_interval); 
          } 
         }, 
         stop: function() { 
          clearInterval(this.autotime); 
          this.autotime = null; 
         }, 
         restart: function() { 
          this.stop(); 
          this.start(); 
         } 
        } 


        var $small = ''; 
        if (!$(".bzoom_small_thumbs").length) { 
         var top = _option.thumb_image_height + 10, 
           width = _option.thumb_image_width, 
           smwidth = (_option.thumb_image_width/_option.small_thumbs) - 10, 
           smheight = smwidth/scxy, 
           ulwidth = 
           smurl = '', 
           html = ''; 

         for (var i = 0; i < _option.small_thumbs; i++) { 
          smurl = $li.eq(i).find('.bzoom_thumb_image').attr("src"); 

          if (i == 0) { 
           html += '<li class="bzoom_smallthumb_active"><img src="' + smurl + '" alt="small" style="width:' + smwidth + 'px; height:' + smheight + 'px;" /></li>'; 
          } else { 
           html += '<li style="opacity:1;"><img src="' + smurl + '" alt="small" style="width:' + smwidth + 'px; height:' + smheight + 'px;" /></li>'; 
          } 
         } 

         $small = $('<li class="bzoom_small_thumbs" style="top:' + top + 'px; width:' + width + 'px;"><ul class="clearfix" style="width: 485px;">' + html + '</ul></li>'); 
         $ul.append($small); 

         $small.delegate("li", "click", function (event) { 
          changeLi($(this).index()); 
          autoPlay.restart(); 
         }); 

         autoPlay.start(); 
        } 

        function changeLi(index) { 
         $ul.find('.bzoom_thumb_active').removeClass('bzoom_thumb_active').stop().animate({opacity: 0}, _option.speed, function() { 
          $(this).hide(); 
         }); 
         $small.find('.bzoom_smallthumb_active').removeClass('bzoom_smallthumb_active').stop().animate({opacity: _option.smallthumb_inactive_opacity}, _option.speed); 

         $li.eq(index).addClass('bzoom_thumb_active').show().stop().css({opacity: 0}).animate({opacity: 1}, _option.speed); 
         $small.find('li:eq(' + index + ')').addClass('bzoom_smallthumb_active').show().stop().css({opacity: _option.smallthumb_inactive_opacity}).animate({opacity: 1}, _option.speed); 

         $bzoom_magnifier_img.attr("src", $li.eq(index).find('.bzoom_thumb_image').attr("src")); 
        } 




        _option.zoom_area_height = _option.zoom_area_width/scxy; 
        $bzoom_zoom_area.find('div').css({width: _option.zoom_area_width, height: _option.zoom_area_height}); 

        $li.add($bzoom_magnifier).mousemove(function (event) { 
         var xpos = event.pageX - $ul.offset().left, 
           ypos = event.pageY - $ul.offset().top, 
           magwidth = _option.thumb_image_width * scalex, 
           magheight = _option.thumb_image_height * scalex, 
           magx = 0, 
           magy = 0, 
           bigposx = 0, 
           bigposy = 0; 

         if (xpos < _option.thumb_image_width/2) { 
          magx = xpos > magwidth/2 ? xpos - magwidth/2 : 0; 
         } else { 
          magx = xpos + magwidth/2 > _option.thumb_image_width ? _option.thumb_image_width - magwidth : xpos - magwidth/2; 
         } 
         if (ypos < _option.thumb_image_height/2) { 
          magy = ypos > magheight/2 ? ypos - magheight/2 : 0; 
         } else { 
          magy = ypos + magheight/2 > _option.thumb_image_height ? _option.thumb_image_height - magheight : ypos - magheight/2; 
         } 

         bigposx = magx/scalex; 
         bigposy = magy/scaley; 

         $bzoom_magnifier.css({'left': magx, 'top': magy}); 
         $bzoom_magnifier_img.css({'left': -magx, 'top': -magy}); 

         $bzoom_zoom_img.css({'left': -bigposx, 'top': -bigposy}); 
        }).mouseenter(function (event) { 
         autoPlay.stop(); 

         $bzoom_zoom_img.attr("src", $(this).find('.bzoom_big_image').attr('src')); 
         $bzoom_zoom_area.css({"background-image": "none"}).stop().fadeIn(400); 

         $ul.find('.bzoom_thumb_active').stop().animate({'opacity': 0.5}, _option.speed * 0.7); 
         $bzoom_magnifier.stop().animate({'opacity': 1}, _option.speed * 0.7).show(); 
        }).mouseleave(function (event) { 
         $bzoom_zoom_area.stop().fadeOut(400); 
         $ul.find('.bzoom_thumb_active').stop().animate({'opacity': 1}, _option.speed * 0.7); 
         $bzoom_magnifier.stop().animate({'opacity': 0}, _option.speed * 0.7, function() { 
          $(this).hide(); 
         }); 

         autoPlay.start(); 
        }) 
       } 
      } 
     })(jQuery); 
    </script> 

私のスタイルシート

<style> 
    .bzoom { direction: ltr; } 
    .bzoom, 
    .bzoom_thumb, 
    .bzoom_thumb_image, 
    .bzoom_big_image, 
    .bzoom_zoom_preview, 
    .bzoom_icon, 
    .bzoom_hint { display: none } 
    .bzoom, 
    .bzoom ul, 
    .bzoom li, 
    .bzoom img, 
    .bzoom_hint, 
    .bzoom_icon, 
    .bzoom_description { 
     margin: 0; 
     padding: 0; 
     border: 0; 
     list-style: none; 
    } 

    .bzoom, 
    .bzoom_magnifier div, 
    .bzoom_magnifier div img, 
    .bzoom_small_thumbs ul, 
    ul .bzoom_small_thumbs li, 
    .bzoom_zoom_area div, 
    .bzoom_zoom_img { position: relative; } 

    .bzoom img, 
    .bzoom li { 
     -webkit-user-select: none; 
     -khtml-user-select: none; 
     -moz-user-select: none; 
     -o-user-select: none; 
     user-select: none; 
     -webkit-user-drag: none; 
     -moz-user-drag: none; 
     user-drag: none; 
    } 

    .bzoom, 
    .bzoom_small_thumbs li { float: left; } 

    .bzoom_right { float: right;} 

    .bzoom li { 
     position: absolute; 
     border: 1px solid #cfcece; 

    } 

    .bzoom img { 
     vertical-align: bottom; 
     width: 50px; 
     height: 70px; 
     border: 1px solid #eaeaea; 
    } 

    .bzoom .bzoom_zoom_area, 
    .bzoom_zoom_area { 
     background: #fff url(./img/loading.gif) center no-repeat; 
     border: 1px solid #ddd; 
     padding: 6px; 
     -webkit-box-shadow: 0 0 10px #ddd; 
     -moz-box-shadow: 0 0 10px #ddd; 
     box-shadow: 0 0 10px #ddd; 
     display: none; 
     z-index: 20; 
    } 

    .bzoom_zoom_area div { overflow: hidden; } 

    .bzoom_zoom_area .bzoom_zoom_img { position: absolute; } 

    .bzoom_wrap .bzoom_magnifier { 
     background: #fff; 
     outline: #bbb solid 1px; 
     display: none; 
     cursor: move; 
    } 

    .bzoom_magnifier div { overflow: hidden; } 

    .bzoom_wrap .bzoom_small_thumbs { overflow: hidden; } 

    .bzoom_wrap .bzoom_small_thumbs li { 
     border: 1px solid #FFF; 
     margin: 0px 10px 0px 0px; 
     position: relative; 
     border: 1px solid #cfcece; 
    } 

    .bzoom_wrap ul li.bzoom_smallthumb_active { 
     -webkit-box-shadow: 0 0 10px #ddd; 
     -moz-box-shadow: 0 0 10px #ddd; 
     box-shadow: 0 0 10px #ddd; 
     border: 1px solid #535353; 
    } 

</style> 
関連する問題