项目中一段js功能代码
$(function(){
//correctPNG();
var clearanceTimes = 4;
var iCurrentPromotions = 0;
var iListImgPage = 1;
var iLiLength = $('#popup_box_good_bodyleftbodyUl li').length;
var iListImgPages = iLiLength/4;
var aListImgArray = new Array();
var iMessageWindowWidth = $('.popup_box_good_bodyleftbody').css('width');
var iMessageWindowHeight = $('.popup_box_good_bodyleftbody').css('height');
$('#popup_box_good_bodyleftbodyUl li').first().css('border-color','#000');
for(var i = 0;i < $('#popup_box_good_bodyleftbodyUl li').length;i++)
{
aListImgArray = $('#popup_box_good_bodyleftbodyUl li').eq(i).html();
}
if(aListImgArray.length % 4 != 0)
{
aListImgArray.length += 4-(aListImgArray.length % 4);
}
iListImgPages = aListImgArray.length / 4;
//showBg();
//$("#model").show();
$('#popup_box_good_bodyleftbodyUl li').click(function (){
var index = $(this).index();
$('#popup_box_good_bodyleftbodyUl li').css('border-color','#a7a7a7');
$(this).css('border-color','#000');
//alert($('.popup_box_good_bodyleftbody_img a').length);
$('.popup_box_good_bodyleftbody_img a').css('display','none');
$('.popup_box_good_bodyleftbody_img a').eq(index+4*(iListImgPage-1)).css('display','block');
});
$('#mask_pic a').click(function (){
$("#mask_pic").hide();
$('.popup_box_good_bodyleftbody').css('width',iMessageWindowWidth).css('height',iMessageWindowHeight);
$('.popup_box_good_bodyleftbody_img img').css('width','100%').css('height','100%');
$('.popup_box_good_bodyright').show();
$('.popup_box_good_bodylefttop').show();
$('.popup_box_good_left').show();
$('.popup_box_good_right').show();
});
$('.popup_box_good_bodyleftbody_img a').click(function (){
var index = $(this).index();
showMask_pic();
$('.popup_box_good_bodyleftbody').css('width','110%').css('height','110%');
$('.popup_box_good_bodyleftbody_img img').css('width','110%').css('height','110%');
$('.popup_box_good_bodyright').hide();
$('.popup_box_good_bodylefttop').hide();
$('.popup_box_good_left').hide();
$('.popup_box_good_right').hide();
});
$('.popup_box_good_bodyleftbodyUlDiv a').not('#popup_box_good_bodyleftbodyUl a').click(function (){
var index = $(this).index();
if(index == 0)
{
if(iListImgPage > iListImgPages)
{
iListImgPage = iListImgPages;
}
if(iListImgPage > 1)
{
for(var i = 0;i iListImgPages)
{
iListImgPage = iListImgPages;
}
if(iListImgPage < iListImgPages)
{
for(var i = 0;i 0){
if(Math.random() < 0.8){
if(clearanceTimes == 1){
clearanceTimes--;
iCurrentPromotions = iCurrentPromotions + iUnt;
var str = '<p>减价成功!获得-'+iUnt+'优惠,最多还有'+clearanceTimes+'次机会</p>';
$('#pick_jj').html(sPick_jjHtml+str);
$('.popup_box_good_bodyright_contentprice b').html(iCurrentPrice-iUnt);
$('#pick_jj').hide();
$('#pick_cgzt').show().find('span').html('您在善品价基础上共赢得了
'+iCurrentPromotions+'元额外优惠,点击“立即抢购”按钮,以最优惠价格把礼物带回家!');
}else{
clearanceTimes--;
iCurrentPromotions = iCurrentPromotions + iUnt;
var str = '<p>减价成功!获得-'+iUnt+'优惠,最多还有'+clearanceTimes+'次机会</p>';
$('#pick_jj').html(sPick_jjHtml+str);
$('.popup_box_good_bodyright_contentprice b').html(iCurrentPrice-iUnt);
}
}else{
//减价失败 最后一搏
clearanceTimes = 0;
$('#pick_jj').hide();
$('#pick_sbxyj').show();
$('#pick_sbxyj a').click(function (){
if(Math.random() < 0.5)
{
//最后一搏成功
iCurrentPromotions = iCurrentPromotions + parseInt($('#pick_sbxyj input').val());
$('.popup_box_good_bodyright_contentprice
b').html(iCurrentPrice-parseInt($('#pick_sbxyj input').val()));
$('#pick_sbxyj').hide();
$('#pick_cgzt').show().find('span').html('您在善品价基础上共赢得了
'+iCurrentPromotions+'元额外优惠,点击“立即抢购”按钮,以最优惠价格把礼物带回家!');
}else{
//最后一搏失败
$('#pick_sbxyj').hide();
$('#pick_sbzt').show();
}
});
}
}else{
//减价失效
//alert('减价机会为0次');
}
});
*/
});
function showContent()
{
$(".popup_box_good_bodyleftbody").hide();
$(".popup_box_good_bodyleftbody2").show();
//$(".popup_box_good_bodylefttopsle").css('left','-3px');
$(".popup_box_good_bodylefttopsle").animate({left:"-3px"});
}
function showImg()
{
$(".popup_box_good_bodyleftbody2").hide();
$(".popup_box_good_bodyleftbody").show();
//$(".popup_box_good_bodylefttopsle").css('left','-68px');
$(".popup_box_good_bodylefttopsle").animate({left:"-68px"});
}
function hideByValue(value){
$(value).hide();
}
function showModel(status){
if(status!=127 && status!=-1 && status!=-2){
Ajax.call('jianlou.php?act=kanjia&goods_id=2923','',ajax_callback,'GET','JSON');
}else{
$(".popup_box_good_bodyright_content_jj").hide();
}
showBg();
$("#model").show();
}
function closeModel(){
$("#fullbg").hide();
$("#model").hide();
}
//显示遮罩层
function showBg() {
var bh = $("body").height();
var bw = $("body").width();
$("#fullbg").css({
height:bh,
width:bw,
display:"block"
});
$("#dialog").show();
$("#mfth_alert").show();
}
function showMask_pic() {
var bh = $("body").height();
var bw = $("body").width();
$("#mask_pic").css({
height:bh,
width:bw,
display:"block"
});
}
function correctPNG(){
for(var i=0; i<document.images.length; i++){
var img = document.images
var imgName = img.src.toUpperCase()
if(imgName.substring(imgName.length-3, imgName.length) == "PNG"){
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + img. + imgTitle
+ " .=."" + "width:" + img.width + "px; height:" + img.height + "px;" + img. + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=.'" + img.src + ".', sizingMethod='scale');."></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
function ajax_callback(result){
var iUnt = parseInt($(this).html());
var sPick_jjHtml = $('#pick_jj').html();
var iCurrentPrice = parseInt($('.popup_box_good_bodyright_contentprice b').html());
if(result[1] == "successed"){
$('#pick_jj').hide();
$('.popup_box_good_bodyright_content_jj').hide();
$('#pick_cgzt').show();
}else if(result[1] == "failed"){
$('#pick_jj').hide();
$('.popup_box_good_bodyright_content_jj').hide();
$('#pick_sbxyj').show();
}else{
//正常杀价
for(var i in result){
var index = i - 1;
$("#content_jj" + i).html("<font .='Ajax.call(."jianlou.php?act=complate&price=" + result + "&index=" + index + ".",.".",ajax_callback2,."GET.",."JSON.");' >" + result + "</font>");
}
}
}
function ajax_callback2(result){
var iUnt = parseInt($(this).html());
var sPick_jjHtml = $('#pick_jj').html();
var iCurrentPrice = parseInt($('.popup_box_good_bodyright_contentprice b').html());
if(result["is_login"] == "ok"){
if(result["status"] == "success"){
var str = "";
str += '<p>减价成功!获得-' + result["price"] + '优惠,最多还有' + (result["index"]) + '次机会</p>';
$('#pick_jj').html(sPick_jjHtml+str);
$('.popup_box_good_bodyright_contentprice b').html(iCurrentPrice-result["price"]);
}else if(result["status"] == "success_end"){
$("#pick_jj").hide();
$(".popup_box_good_bodyright_content_jj").hide();
$("#pick_cgzt").show();
}else{
clearanceTimes = 0;
$('#pick_jj').hide();
$('#pick_sbxyj').show();
/*$('#pick_sbxyj a').click(function (){
if(Math.random() < 0.5){
//最后一搏成功
iCurrentPromotions = iCurrentPromotions + parseInt($('#pick_sbxyj input').val());
$('.popup_box_good_bodyright_contentprice b').html(iCurrentPrice-parseInt($('#pick_sbxyj input').val()));
$('#pick_sbxyj').hide();
$('#pick_cgzt').show().find('span').html('您在善品价基础上共赢得了
'+iCurrentPromotions+'元额外优惠,点击“立即抢购”按钮,以最优惠价格把礼物带回家!');
}else{
//最后一搏失败
$('#pick_sbxyj').hide();
$('#pick_sbzt').show();
}
});
*/
}
}else if(result["is_login"] == "none"){
alert("请先登录");
window.location.href = "user.php";
}
}
function want_kill_click(){
var want_kill_price = $("#want_kill_price").val();
if(want_kill_price){
Ajax.call('jianlou.php?act=want_price&goods_id=2923&want_kill_price='+want_kill_price,'',ajax_callback3,'GET','TEXT');
}
}
function ajax_callback3(result){
if(result == "want_ok"){
$('#pick_jj').hide();
$('.popup_box_good_bodyright_content_jj').hide();
$('#pick_cgzt').show();
$('#pick_sbxyj').hide();
}else if(result == "want_fail"){
$('#pick_jj').hide();
$('.popup_box_good_bodyright_content_jj').hide();
$('#last_kill_price').hide();
$('#pick_cgzt').hide();
$('#pick_sbxyj').show();
}else{
alert("误操作!");
}
}