脚本宝典收集整理的这篇文章主要介绍了js实现模拟购物商城案例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
学习HTML,css和js前端的小伙伴们,这次来分享购物商城案例的实现!
准备一些需要放到页面上的图片,小图和其对应的大图,博主这边举例为小图(40 x 40),大图(321 x 430)。
对div标签进行设置(对边框属性进行设置):
对table标签进行设置(不需要边框,且离顶部有一定的距离):
鼠标进入的函数:
function oPErInimg(img,src){ //设置图片的样式 img.style.border="solid 1px blue"; //设置大图的img路径 //获取大图路径 VAR Big = document.getElementById("big"); //设置路径 big.src=src; } function operOutImg(img){ //设置图片的样式 img.style.border=""; }
鼠标移出函数:
function operOutImg(img){ //设置图片的样式 img.style.border=""; }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <meta name="viewport" content="width=device-width, inITial-scale=1.0"> <!--声明js代码域--> <script> //创建函数进行照片的联动和样式设置 function operInImg(img,src){ //设置图片的样式 img.style.border="solid 1px blue"; //设置大图的img路径 //获取大图路径 var big = document.getElementById("big"); //设置路径 big.src=src; } function operOutImg(img){ //设置图片的样式 img.style.border=""; } </script> <!---声明css代码域--> <style> /*设置div样式*/ #showdiv{ width: 342px; height: 505px; border: solid 1px ; border-radius: 10px; } /*设置table样式*/ #ta{ margin: auto; margin-top: 5px; } </style> <title>taobao</title> </head> <body> <div id="showdiv"> <table width ="332px" height = "440px" id="ta"> <tr height="300px"> <td colspan="5"><img src="./images/demo-big.jpg" alt="" id="big"></td> </tr> <tr height="40px"> <td><img src="./images/demo01.jpg" alt="" onmouseover="operInImg(this,'./images/demo-big01.jpg')" onmouseout="operOutImg(this)"></td> <td><img src="./images/demo02.jpg" alt="" onmouseover="operInImg(this,'./images/demo-big02.jpg')" onmouseout="operOutImg(this)"> </td> <td><img src="./images/demo03.jpg" alt="" onmouseover="operInImg(this,'./images/demo-big03.jpg')" onmouseout="operOutImg(this)"> </td> <td><img src="./images/demo04.jpg" alt="" onmouseover="operInImg(this,'./images/demo-big04.jpg')" onmouseout="operOutImg(this)"> </td> <td><img src="./images/demo05.jpg" alt="" onmouseover="operInImg(this,'./images/demo-big05.jpg')" onmouseout="operOutImg(this)"> </td> </tr> </table> </div> </body> </html>
实现效果:
感谢您的阅读,不足之处欢迎指正!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本宝典。
以上是脚本宝典为你收集整理的js实现模拟购物商城案例全部内容,希望文章能够帮你解决js实现模拟购物商城案例所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。