menu

jquery

zoomType: ‘reverse’ //设置放大镜的类型

zoomType:   默认值为standard。如果设为reverse,在小图片仲,移入鼠标时,所选区域高亮,非选中区域淡灰色。

$.each() 与$().each()

jQuery.each()方法:

  • jQuery.each() 函数用于遍历指定的对象和数组;

  • 语法: $.each( object, callback )

    • object: Object类型 指定需要遍历的对象或数组;

    • callback: Function类型 指定的用于循环执行的函数:

      • function(index, value)
      • index:表示遍历的数组的下标;
      • value:表示下标对应的值;
      $(function () { 
          $.each([52, 97], function(index, value) {
          	alert(index + ': ' + value);
          });
      })
      //运行结果:
      0:52   1:97
      

jQuery each() 方法

  • each() 方法为每个匹配元素规定要运行的函数。

  • 语法: $(selector).each(function(index,element))

    • function(index,element) 必需。为每个匹配元素规定运行的函数;

    • index - 选择器的 index 位置;

    • element - 当前的元素(也可使用 “this” 选择器)。

      //html-------------------
      <button>输出每个列表项的值</button>
      <ul>
          <li>Coffee</li>
          <li>Milk</li>
          <li>Soda</li>
      </ul>
      //js---------------------
      $("button").click(function(){
          $("li").each(function(){
              alert($(this).text())
          });
      });
      //运行结果---------------
      //弹框依次弹出:  Coffee    Milk   Soda
      
  • mouseover/mouseout事件,子元素被移入移出,也会触发父元素的事件

  • mouseenter/mouseleave事件,子元素被移入移出,不会触发父元素的事件(推荐使用)

  • hover事件,移入移出,可以添加两个参数,也可以只添加一个参数。

    $(".father").hover(function(){
    	console.log("father被移入移出了");
    });
    
    $(".father").hover(function(){
    	console.log("father被移入了");
    },function(){
    	console.log("father被移出了");
    });
    
  • 监听网页滚动

    $(function(){

    ​ //1.监听网页的滚动

    ​ $(window).scroll(function(){

    ​ //1.1获取网页滚动的偏移位

    ​ var offset = $(“html,body”).scrollTop();

    ​ //1.2判断网页是否滚动到了指定的位置

    ​ if(offset >= 500){

    ​ //1.3显示广告

    ​ $(“img”).show(1000);

    ​ }

    ​ });

    });