channel.js 22.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
/*************************************************
 *  Function  channel
 *  Copyright frontEnd http://www.tp-shop.cn/
 *  Designed and built by frontEnd  @yangyang.li
 *  Date 2016/03/14
 ************************************************/

/**
 ** all plug-in
 ** @@1 移除边框边距
 **/ 

;(function($){

	// @@1
	$.fn.removeBorMar = function(options){  

		var defaults = {},

		    ops= $.extend({},defaults,options),

		    $ts = $(this);

		if($ts.length){

			// 清除边框
			$ts.css("border","none");

		}
	}

	function rmbr(cls){

		var cls = cls || ".g-rmb";

		$(cls).find("li:last").css("border","none");

	}

	return rmbr();

})(jQuery);


/**
 懒加载
 **/

 $(function(){
    //延迟加载
    $(".fn_img_lazy").lazyload({

        placeholder: "",

        threshold: 0,

        effect: "show",

        skip_invisible: false
    }); 

 });


var indexEffect = {

	init:function(){

		var $self = this;

        if($(".m-flr").length){

            $self.floors();

        }
			
		$self.navShow(".m-lst li",".m-dtl .g-snv","svn");        

	},

	navShow:function(){

		var arg1 = arguments[0],

			arg2 = arguments[1],

			arg3 = arguments[2] || undefined;

		$(arg1).mouseenter(function() {

			var ts = $(this);

			tm = setTimeout(function() {

				var idx = ts.index();

				$(arg1).removeClass('s-select').eq(idx).addClass('s-select');

				if(arg3 != "undefined"){

					$(arg2).eq(idx).css("margin-top",idx*32+40);

				}
				
				$(arg2).hide().eq(idx).show();

			}, 50);

		}).mouseleave(function() {
			/* Act on the event */
			clearTimeout(tm);

		});

		if(arg3 != "undefined"){

			$(".m-sld-lst").on("mouseleave",function(){

				$(arg1).removeClass('s-select');

				$(arg2).hide();

			});

		}


	},

	// floor
	floors:function(){

		var offsettop = $(".m-flr:first").offset().top,

			yCenter = $(window).height() / 2;
		
		// console.log(document.body.scrollTop)

		// 判断楼层显示
		$(window).scroll(function(event) {

			var scrolltop = $(window).scrollTop();

			if(offsettop - scrolltop <= 150) {

				$(".g-ab-fx").show();

				$(".g-flr").css({"opacity":1,"transform":"scale(1)","visibility":"visible"});

			}else{

				$(".g-flr").css({"opacity":0,"transform":"scale(1.2)","visibility":"hidden"});

				$(".g-ab-fx").removeAttr("style");

			}	

			// 右侧楼层挂件联动左侧楼层
			var $lf_flr = $(".m-flr");

			$lf_flr.each(function(idx,el){

				var $ts = $(this),

					off_top = $ts.offset().top,

					f_bottom = $ts.offset().top + $ts.outerHeight();

				if (scrolltop + yCenter > off_top && scrolltop + yCenter < f_bottom) { 

					$(".g-flr li").eq(idx).addClass('s-select').siblings().removeClass('s-select');

				}

			});


		});

		// 锚点点击跳转到相应楼层
		$(".g-flr").on( "click" , "li" , function(){

            if(!$(this).hasClass('backtop')){

    			var $index = $(this).index(),	

    				$hei = $(".m-flr").eq($index).offset().top - 150;

    			$(".g-flr li").removeClass('s-select').eq($index).addClass('s-select');

    			$("html,body").stop(true,true).animate({"scrollTop":$hei},400);

            }

		});
	}
}  

// removeborder 
function removeborder(){
    // 移除边框
    $(".m-lst li:last").find("dl").removeBorMar();
}

window.onload = removeborder;

var main = {
    init:function(){
        // 绑定方法
        this.bindEvent();
        // floor tab
        this.floorTab();
    },

    bindEvent:function(){
        // TO DO
        // 主大图轮播
        $('#slideMain').fn_slide({

            has_num: false,

            type: "fadeIn",

            time: 5000,

            auto: true,

            hide_page_btn: true

        });

        // 右侧广告
        $('#slideAd').fn_slide({

            has_num: false,

            type: "move",

            flip: false
        });

        // 判断右侧广告图是否存在设定宽
        var sId = $("#slideAd"),

            sSlide = $("#slideMain"),

            nWid = 1000,

            nWid2 = 714,

            nMar = 440;

        if(sId.find(".slider-main li").length === 0){

            sSlide.find(".slider-nav").css({

                "width": nWid +"px"

            });

             sSlide.find(".J_page_box .slider-next").css({

                "margin-left": nMar +"px"

            });

        }else{

            sSlide.find(".slider-nav").css({

                "width": nWid2 +"px"

            });

        }

        // floor slide 
        $('.J-f-sld').fn_slide({

            has_num: false,

            type: "move",

            auto: true,

            time: 5000,

            hide_page_btn: true
        });

        // 下期预告
        $(".J_pictureArea").each(function() {

            var self = $(this);

            self.find("li img[data-src]").each(function(key,item) {

                $(item).attr("src", $(item).attr("data-src")).removeAttr("data-src");

            });

        });
        // 默认展示轮播图背景
        this.bgChange(0);
    },

    floorTab:function(){

        var sTab = ".J-tab li",

            sTabCnt = ".J-tabConent .J-hide",

            sflr = ".m-flr",

            fTime = null;

        $(sflr).each(function(){

            $(this).find(sTab).eq(0).addClass('z_select');

            $(this).find(sTabCnt).hide().eq(0).show();
            
        });   

        $(document).on({
            
            "mouseenter":function(){

                var oTs = $(this);

                fTime = setTimeout(function(){

                    var sIndex = oTs.index();

                    oTs.addClass('z_select').siblings().removeClass('z_select');

                    oTs.parents(".J-parent").find(sTabCnt).hide().eq(sIndex).show();

                },300);

            },

            "mouseleave":function(){

                clearTimeout(fTime);

            }

        },sTab);

    },


    bgChange:function(index){
        // TO DO
        var sBgpic = $("#slideMain").find(".slider-main li").eq(index).attr("data-bgimage"),

            sBgColor = $("#slideMain").find(".slider-main li").eq(index).attr("data-bgcolor");

        if(typeof sBgpic === "undefined" && typeof sBgColor === "undefined") {

            $("#bgcolor").removeAttr("style");

        }
        else if(typeof sBgpic !== "undefined" && typeof sBgColor === "undefined"){

            $("#bgcolor").css("background","url("+sBgpic+") no-repeat center top");

        }
        else if(typeof sBgpic === "undefined" && typeof sBgColor !== "undefined"){

            $("#bgcolor").css("background",sBgColor);

        }
    }
}

$(function(){
    main.init();
    indexEffect.init();
});

;(function($) {
	
    $.fn.fn_slide = function(options) {
        // build main options before element iteration
        var opts = $.extend({}, $.fn.fn_slide.defaults, options);
        // iterate and reformat each matched element
        return this.each(function() {

            var $this = $(this);

            // build element specific options
            var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

            var active = opts.active || "z-select",
                time = null;

            var ele = {

                main: "slider-main",

                num: "slider-nav",

                num_li: "slider-item",

                next_btn: "slider-next",

                prev_btn: "slider-prev",

                page_box:"J_page_box"

            };

            //get img contains
            var _ul = $this.children('.' + ele.main);
            //get li's length
            var _len = _ul.children("li").length;
            //create slide Ctrl
            var str = "";
            //init _index
            var _index = 0;

            var _height = _ul.children("li").height();

            var _width = $this.width();

            //set ul's width
            _ul.width(_width * _len);
            //set li's width
            //_ul.children("li").width(_width);

            var obj = {

                is_flip: o.flip,

                is_fade: (o.type === "fadeIn"),

                is_move: (o.type === "move"),

                is_up: (o.type === "up"),

                throttle_t: 200,

                init: function() {

                    //ctrl
                    o.has_ctrl && $this.append('<ul class="s-ctr ' + ele.num + '">' + showCtrl() + '</ul>');

                    // 当前图片为1 圆点隐藏
                    if(_len <= 1) {
                        $this.find("." + ele.num).hide();
                    }

                    //是否需要上一页下一页
                    obj.is_flip && showFlip();

                    //初始化渐变还是左右
                    if (obj.is_fade) {

                       _ul.children("li:first").addClass('z-select').css({
                            "position": "absolute",
                            "zIndex": 1,
                            "opacity": 1
                        })
                            .siblings().removeClass('z-select').css({
                                "position": "absolute",
                                "zIndex": 0,
                                "opacity": 0
                            });

                        //todo
                        $this.on('mouseenter', '.' + ele.num_li, function() {

                            var $this = $(this);

                            clearTimeout(time);

                            time = setTimeout(function(){

                                _index = $this.index();

                                _ul.children("li").eq(_index).addClass('z-select').css("zIndex", 1).siblings().removeClass('z-select').css("zIndex", 0);

                                _ul.children("li").eq(_index).stop(true).animate({

                                    "opacity": 1

                                }, {
                                    duration: o.duration,

                                    complete: function() {

                                        _ul.children("li").eq(_index).siblings().css({
                                            "opacity": 0
                                        });

                                    }

                                });

                               $this.addClass(active).siblings().removeClass(active);

                               // roll 大背景底
                               if($this.parents("#slideMain").length){

                                    main.bgChange(_index);

                               }                               

                            },obj.throttle_t);


                        }).on('mouseleave', '.' + ele.num_li, function() {

                            clearTimeout(time);

                        });


                    } else if (obj.is_move) {

                        //bind event on <li>
                        $this.on('mouseenter', '.' + ele.num_li, function() {

                            var $this = $(this);

                            clearTimeout(time);

                            time = setTimeout(function(){

                                _index = $this.index();

                                _ul.stop(true).animate({

                                    "marginLeft": -(_width * _index)

                                }, o.duration);

                                $this.addClass(active).siblings().removeClass(active);

                            },obj.throttle_t);


                        }).on('mouseleave', '.' + ele.num_li, function() {

                            clearTimeout(time);

                        });


                    } else if (obj.is_up) {//晒单向上滚动

                        _ul.width(_width);

                        _ul.height(_height * _len);

                    }

                    //如果上下页切换按钮是隐藏的话

                    o.hide_page_btn && $this.on({

                        mouseenter:function(){

                            if($(this).find("."+ele.page_box).is(":hidden") && $(this).find("."+ele.main+" >li").length >1){

                                $(this).find("."+ele.page_box).show();

                            }

                        },

                        mouseleave:function(){

                            $(this).find("."+ele.page_box).hide();

                        }

                    });

                    //定时器
                    obj.timeFuc();

                },

                timeFuc: function() {

                    //auto 为true 表示可自动

                    if(o.auto && _len >1){

                        //setInterval
                        time = setInterval(showEffect, o.time);

                        // clearInterval
                        $this.on({

                            mouseenter: function() {

                                clearInterval(time);

                            },
                            mouseleave: function() {

                                clearInterval(time);

                                time = setInterval(showEffect, o.time);

                            }

                        });

                    }

                }

            };

            //初始化
            obj.init();

            //1->next 0->prev
            function showEffect() {


                if (o.type === "fadeIn") {

                    arguments.length ? _index-- : _index++;

                    if (_index === -1) {

                        _index = _len - 1;

                    } else if (_index === _len) {

                        _index = 0;

                    }

                    _ul.children("li").eq(_index).addClass('z-select').css("zIndex", 1).siblings().removeClass('z-select').css("zIndex", 0);
                    _ul.children("li").eq(_index).stop(true).animate({

                        "opacity": 1

                    }, {
                        duration: o.duration,

                        complete: function() {

                            _ul.children("li").eq(_index).siblings().css({
                                "opacity": 0
                            });

                        }

                    });

                    $this.find("." + ele.num_li).eq(_index).addClass(active).siblings().removeClass(active);

                    // roll 大背景底
                    if($this.length){

                        main.bgChange(_index);

                    }

                } else if (o.type === "move") {

                    if (arguments.length) {

                        if (_index === 0) {

                            _index--;

                            _ul.children("li:last").css({

                                "position": "relative",

                                "left": -_len * _width

                            });

                            _ul.stop(true).animate({

                                "marginLeft": -_index * _width

                            }, {
                                duration: o.duration,

                                complete: function() {

                                    _ul.children("li:last").attr("style", "width:" + _width + "px");

                                    _ul.css("marginLeft", -_width * (_len - 1));
                                }

                            });

                            $this.find("." + ele.num_li).eq(_len - 1).addClass(active).siblings().removeClass(active);

                            _index = _len - 1;

                        } else {

                            _index--;

                            _ul.stop(true).animate({

                                "marginLeft": -_width * _index

                            }, o.duration);

                            $this.find("." + ele.num_li).eq(_index).addClass(active).siblings().removeClass(active);
                        }

                    } else {

                        if (_index === (_len - 1)) {

                            _index++;

                            _ul.children("li:first").css({

                                "position": "relative",

                                "left": _index * _width

                            });

                            _ul.stop(true).animate({
                                "marginLeft": -_width * _index
                            }, {
                                duration: o.duration,
                                complete: function() {

                                    _ul.children("li:first").attr("style", "width:" + _width + "px");

                                    _ul.css("marginLeft", 0);
                                }

                            });

                            $this.find("." + ele.num_li).eq(0).addClass(active).siblings().removeClass(active);

                            _index = 0;

                        } else {

                            _index++;

                            _ul.stop(true).animate({

                                "marginLeft": -_width * _index

                            }, o.duration);

                            $this.find("." + ele.num_li).eq(_index).addClass(active).siblings().removeClass(active);
                        }

                    }

                } else if (o.type === "up") {

                    if (_len > 2) {

                        if (arguments.length) {

                            if (_index === 0) {

                                _index--;

                                _ul.children("li:last").css({

                                    "position": "relative",

                                    "top": -_len * _height

                                });

                                _ul.stop(true).animate({

                                    "marginTop": -_index * _height

                                }, {
                                    duration: o.duration,

                                    complete: function() {

                                        _ul.children("li:last").attr("style", "width:" + _width + "px");

                                        _ul.css("marginTop", -_height * (_len - 1));
                                    }

                                });

                                $this.find("." + ele.num_li).eq(_len - 1).addClass(active).siblings().removeClass(active);

                                _index = _len - 1;

                            } else {

                                _index--;

                                _ul.stop(true).animate({

                                    "marginTop": -_height * _index

                                }, o.duration);

                                $this.find("." + ele.num_li).eq(_index).addClass(active).siblings().removeClass(active);
                            }

                        } else {

                            if (_index === (_len - 2)) {

                                _index++;

                                _ul.children("li:first").css({

                                    "position": "relative",

                                    "top": _len * _height

                                });

                                _ul.children("li").eq(1).css({

                                    "position": "relative",

                                    "top": (_len) * _height

                                });

                                _ul.stop(true).animate({
                                    "marginTop": -_height * _index
                                }, o.duration);

                                $this.find("." + ele.num_li).eq(0).addClass(active).siblings().removeClass(active);

                            } else if (_index === (_len - 1)) {

                                _index++;

                                _ul.stop(true).animate({
                                    "marginTop": -_height * _len
                                }, {
                                    duration: o.duration,
                                    complete: function() {

                                        _ul.children("li:first").attr("style", "width:" + _width + "px");

                                        _ul.children("li").eq(1).attr("style", "width:" + _width + "px");

                                        _ul.css("marginTop", 0);
                                    }

                                });

                                $this.find("." + ele.num_li).eq(0).addClass(active).siblings().removeClass(active);

                                _index = 0;

                            } else {

                                _index++;

                                _ul.stop(true).animate({

                                    "marginTop": -_height * _index

                                }, o.duration);

                                $this.find("." + ele.num_li).eq(_index).addClass(active).siblings().removeClass(active);
                            }

                        }

                    }

                }

            }

            //function - foreach slideCtrl
            function showCtrl() {

                var c_name = null;

                for (var i = 0, j = _len; i < j; i++) {

                    c_name = ele.num_li + (i === 0 ? " " + active + "" : "");

                    str += "<li class='" + c_name + "'>" + (o.has_num ? (i + 1) : "") + "</li>";

                }

                return str;
            }

            //is or not flip
            function showFlip() {

                $this.append('<div class="s-pg '+ele.page_box+'"><a href="javascript:;" class="s-prev ' + ele.prev_btn + '"><</a><a href="javascript:;" class="s-next ' + ele.next_btn + '">></a></div>');

                if(o.hide_page_btn){

                    $("."+ele.page_box).hide();

                }

                $this.on("click", "." + ele.prev_btn, throttle(function() {

                    clearInterval(time);

                    showEffect("prev");

                }, obj.throttle_t));

  
                $this.on("click", "." + ele.next_btn, throttle(function() {

                    clearInterval(time);

                    showEffect();

                }, obj.throttle_t));

            }

            //event 节流
            function throttle(fn, interval) {
                var doing = false;

                return function() {
                    if (doing) {
                        return;
                    }
                    doing = true;
                    fn.apply(this, arguments);
                    setTimeout(function() {
                        doing = false;
                    }, interval);
                };
            }

        });
    };

    //this defaults
    $.fn.fn_slide.defaults = {
        //滚动间隔时间
        time: 3000,
        //过渡间隔
        duration: 300,
        //方向
        direction: 'left',
        //是否有数字
        has_num: true,
        //动画的效果
        type: "fadeIn",  //move
        //是否有分页
        flip: true,
        //是否自动播放
        auto:false,
        //是否有数字控制
        has_ctrl:true,
        //是否需要隐藏左右点击按钮
        hide_page_btn:false
    };

})(jQuery);