如何使用openSpeDiv方法实现Ecshop登录弹窗框效果
这篇文章主要介绍如何使用openSpeDiv方法实现Ecshop登录弹窗框效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
玉州网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联公司2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
在ECSHOP的目录/JS/common.js中有一个openSpeDiv方法是实现ECSHOP的弹窗效果的。如果我们想制作一个登录弹窗框,可以截取这个方法里的部分代码。
//生成属性选择层 function openSpeDiv(message, goods_id, parent) { var _id = "speDiv"; var m = "mask"; if (docEle(_id)) document.removeChild(docEle(_id)); if (docEle(m)) document.removeChild(docEle(m)); //计算上卷元素值 var scrollPos; if (typeof window.pageYOffset != 'undefined') { scrollPos = window.pageYOffset; } else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { scrollPos = document.documentElement.scrollTop; } else if (typeof document.body != 'undefined') { scrollPos = document.body.scrollTop; } var i = 0; var sel_obj = document.getElementsByTagName('select'); while (sel_obj[i]) { sel_obj[i].style.visibility = "hidden"; i++; } // 新激活图层 var newDiv = document.createElement("div"); newDiv.id = _id; newDiv.style.position = "absolute"; newDiv.style.zIndex = "10000"; newDiv.style.width = "300px"; newDiv.style.height = "260px"; newDiv.style.top = (parseInt(scrollPos + 200)) + "px"; newDiv.style.left = (parseInt(document.body.offsetWidth) - 200) / 2 + "px"; // 屏幕居中 newDiv.style.overflow = "auto"; newDiv.style.background = "#FFF"; newDiv.style.border = "3px solid #59B0FF"; newDiv.style.padding = "5px"; //生成层内内容 newDiv.innerHTML = '' + select_spe + "
"; for (var spec = 0; spec < message.length; spec++) { newDiv.innerHTML += '' + message[spec]['name'] + ' '; if (message[spec]['attr_type'] == 1) { for (var val_arr = 0; val_arr < message[spec]['values'].length; val_arr++) { if (val_arr == 0) { newDiv.innerHTML += "" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']
'; } else { newDiv.innerHTML += "" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']
'; } } newDiv.innerHTML += ""; } else { for (var val_arr = 0; val_arr < message[spec]['values'].length; val_arr++) { newDiv.innerHTML += "" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']
'; } newDiv.innerHTML += ""; } } newDiv.innerHTML += "[" + btn_buy + "] [" + is_cancel + "] "; document.body.appendChild(newDiv); // mask图层 var newMask = document.createElement("div"); newMask.id = m; newMask.style.position = "absolute"; newMask.style.zIndex = "9999"; newMask.style.width = document.body.scrollWidth + "px"; newMask.style.height = document.body.scrollHeight + "px"; newMask.style.top = "0px"; newMask.style.left = "0px"; newMask.style.background = "#FFF"; newMask.style.filter = "alpha(opacity=30)"; newMask.style.opacity = "0.40"; document.body.appendChild(newMask); } var i = 0; var sel_obj = document.getElementsByTagName('select'); while (sel_obj[i]) { sel_obj[i].style.visibility = "hidden"; i++; }
上面代码是与下拉选择框有关,去掉。
for (var spec = 0; spec < message.length; spec++)
{
newDiv.innerHTML += '
' + message[spec]['name'] + ' ';
if (message[spec]['attr_type'] == 1)
{
for (var val_arr = 0; val_arr < message[spec]['values'].length; val_arr++)
{
if (val_arr == 0)
{
newDiv.innerHTML += "" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']
';
}
else
{
newDiv.innerHTML += "" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']
';
}
}
newDiv.innerHTML += "";
}
else
{
for (var val_arr = 0; val_arr < message[spec]['values'].length; val_arr++)
{
newDiv.innerHTML += "" + message[spec]['values'][val_arr]['label'] + ' [' + message[spec]['values'][val_arr]['format_price'] + ']
';
}
newDiv.innerHTML += "";
}
}
newDiv.innerHTML += "
[" + btn_buy + "] [" + is_cancel + "] ";
上面这与弹窗框里的内容有关,也去掉。
要制作一个登录弹窗框,我们再把需要传入的参数去掉,改一下方法名,var _id和var m的值,然后在newDiv.innerHTML 里面加上你想在弹窗框显示的HTML代码即可改写该方法。
新方法如下:
//弹窗登录 function openLoginDiv() { var _id = "loginDiv"; var m = "loginMask"; if (docEle(_id)) document.removeChild(docEle(_id)); if (docEle(m)) document.removeChild(docEle(m)); //计算上卷元素值 var scrollPos; if (typeof window.pageYOffset != 'undefined') { scrollPos = window.pageYOffset; } else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { scrollPos = document.documentElement.scrollTop; } else if (typeof document.body != 'undefined') { scrollPos = document.body.scrollTop; } // 新激活图层 var newDiv = document.createElement("div"); newDiv.id = _id; newDiv.style.position = "absolute"; newDiv.style.zIndex = "10000"; newDiv.style.width = "300px"; newDiv.style.height = "260px"; newDiv.style.top = (parseInt(scrollPos + 200)) + "px"; newDiv.style.left = (parseInt(document.body.offsetWidth) - 200) / 2 + "px"; // 屏幕居中 newDiv.style.overflow = "auto"; newDiv.style.background = "#FFF"; newDiv.style.border = "3px solid #59B0FF"; newDiv.style.padding = "5px"; //生成层内内容 newDiv.innerHTML = ''; document.body.appendChild(newDiv); // mask图层 var newMask = document.createElement("div"); newMask.id = m; newMask.style.position = "absolute"; newMask.style.zIndex = "9999"; newMask.style.width = document.body.scrollWidth + "px"; newMask.style.height = document.body.scrollHeight + "px"; newMask.style.top = "0px"; newMask.style.left = "0px"; newMask.style.background = "#FFF"; newMask.style.filter = "alpha(opacity=30)"; newMask.style.opacity = "0.40"; document.body.appendChild(newMask); }
然后在themes/default/library/page_header.lbi文件上把弹窗登录按钮显示到你想添加的位置,加上这一代码段:
弹窗登录
再修改一下样式,让其更漂亮。样式修改在模板目录themes/default/style.css。加上这一段:
#ajax_loginForm{padding:10px; line-height:2em;} #ajax_loginForm input{width:98%; height:35px; padding:0 1%; line-height:35px; border:1px solid #e7e7e7; border-radius:3px;} #ajax_loginForm button{background:#ff6599; border: none; color:#fff; font-size:16px; border-radius:3px; padding:5px 15px; cursor:pointer;}
最后再写个关闭弹窗的js事件即可。方法我写在common.js文件下的openLoginDiv()之后
function closeLoginForm(){ document.body.removeChild(docEle('loginDiv')); document.body.removeChild(docEle('loginMask')); }
效果如图:
以上是“如何使用openSpeDiv方法实现Ecshop登录弹窗框效果”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
新闻名称:如何使用openSpeDiv方法实现Ecshop登录弹窗框效果
网站地址:http://cdiso.cn/article/ighjpg.html