$(function () {
var attributes = JSON.parse('""');
var pictures = JSON.parse('[{"id":148006,"product_id":8532,"image_url":["\/uploads\/uk\/product\/CL7U-U3\/CL7U-U3-800-1.jpg","\/uploads\/uk\/product\/CL7U-U3\/CL7U-U3-800-SIZE.jpg"],"image_sort":0,"image_desc":"","image_color":[]}]');
//多属性选择及绑定事件
$(".hd .attr_item").click(function(){
$(this).siblings().removeClass('on');
$(this).toggleClass('on');
var attrVal = $(this).data('feed');
if($(this).hasClass("on")){
$(this).parents(".hd").find(".selectedAttr").text(attrVal);
}
else{
$(this).parents(".hd").find(".selectedAttr").html('');
}
//验证是否所有属性全部选中
var skuCount = $('.attr_type').length;
var activeCount = $('.hd .on').length;
var productAttr = skuAttrType();
if(activeCount == skuCount)
{
//勾选属性事件: 重新加载属性图片
pictures.forEach(function(image, key) {
//选中的属性
var imageColor = image.image_color;
//判断属性是否全部匹配
var attrFlag = true;
attributes.forEach(function(attrName, kat) {
//console.log(imageColor[kat][attrName] + '=====+++++====' + productAttr[kat][attrName]);
if(imageColor[kat][attrName] == productAttr[kat][attrName]){
}else{
attrFlag = false;
return;
}
})
if(attrFlag){
var smaImagesHtml = '';
var bigImagesHtml = '';
var firstImage = '';
var imageUrl = image.image_url;
imageUrl.forEach(function(atrVal,atrKey) {
if(atrKey == 0) {
$("#midimg").attr('src', atrVal);
}
bigImagesHtml += '
';
smaImagesHtml += '
';
});
$("#image_list").html(bigImagesHtml);
$("#mswiper-list").html(smaImagesHtml);
}
})
}
});
});
function skuAttrType(){
// 获取规格值
var spec = [];
$('.hd .on').each(function()
{
var typeName = $(this).data('type');
var selected = {};
selected[typeName] = $(this).data('value');
spec.push(selected);
});
return JSON.parse(JSON.stringify(spec));
}
$(function () {
var $category = $(".ans .anbox");
$category.hide();
$(".ans .antit").click(function () {
if ($(this).next(".anbox").is(":visible")) {
$(this).removeClass('on').next().slideUp(800);
$(this).parent('.ans').removeClass('on');
$(this).children("i").removeClass("ons")
} else {
$category.hide();
$(".ans .antit").removeClass('on');
$(this).children("i").addClass("ons")
$(this).addClass('on').next().slideDown(800);
$(this).parent('.ans').addClass('on');
}
});
});
$(function () {
$('a[href*=#],area[href*=#]').click(function () {
console.log(this.pathname)
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
var targetOffset = $target.offset().top - 50;
$('html,body').animate({
scrollTop: targetOffset
}, 800);
return false; //页面锚点跳转动画 后面的800是锚点跳转的时间 800ms
}
}
});
})
$(document).ready(function () {
//获取div-one距离顶部的距离
var navtop = $(".warpa").offset().top;
$(document).scroll(function () {
//获取滚动条滚动的高度
var scroltop = $(document).scrollTop();
if (scroltop > navtop) {
$(".warpa").css({
"position": "fixed",
"top": "0px",
"left": "0px",
"right": "0px",
"z-index": "999"
})
} else {
$(".warpa").css({
"position": "",
"top": "",
"left": "",
"right": "",
"z-index": ""
})
}
})
})
$("input").click(function () {
$(this).siblings("div").children("span").addClass("active");
$(this).parents("div").siblings("div").find("span").removeClass("active");
});
$(function () {
$(window).scroll(function () {
var arr = []
$.each($(".proTfg"), function (k, v) {
arr[k] = $(this).offset().top + $(this).height();
})
$.each(arr, function (k, v) {
if (($(window).scrollTop() + $(".cpa li").eq(k - 1).height() + 10) < v) {
if (!$(".cpa li").eq(k).hasClass("current")) {
$(".cpa li").eq(k).attr("class", "current").siblings().removeClass();
}
return false;
}
})
})
})