2025年小实习项目 - 仿写京东商城 - CSS+JS+HTML

小实习项目 - 仿写京东商城 - CSS+JS+HTML二 代码实现 项目目录 主页面 CSS 部分 好像有点多 截图吧 Slider 实现 export class Slider constructor id this box document querySelecto id this picBox

大家好,我是讯享网,很高兴认识大家。


讯享网

二、代码实现


1.项目目录

2.主页面CSS部分

好像有点多 截图吧

3.Slider实现

export class Slider {

constructor(id){

this.box = document.querySelector(id)

this.picBox = this.box.querySelector(“ul”)

this.indexBox = this.box.querySelector(“.index-box”)

this.sliderWidth = this.box.clientWidth

this.sliders = this.picBox.children.length

this.index = 1

this.animated = false

this.auto = null

this.init()

}

init(){

this.initPoint()

this.copyPic()

this.leftRight()

this.play()

}

initPoint(){

const num = this.picBox.children.length;

let frg = document.createDocumentFragment();

for(let i = 0; i < num; i++){

let li = document.createElement(“li”)

li.setAttribute(“data-index”, i+1)

if(i == 0) li.className = “active”

frg.appendChild(li)

}

this.indexBox.children[0].style.width = num * 10 * 2 + “px”;

this.indexBox.children[0].appendChild(frg)

this.indexBox.children[0].addEventListener(“click”, (e) => {

console.log(“point”)

let pointIndex = (e.target).getAttribute(“data-index”)

if(pointIndex == this.index || this.animated){

return

}

let offset = (pointIndex - this.index) * this.sliderWidth

this.index = pointIndex

this.move(offset)

})

}

copyPic(){

const first = this.picBox.firstElementChild.cloneNode(true)

const last = this.picBox.lastElementChild.cloneNode(true)

this.picBox.appendChild(first)

this.picBox.insertBefore(last, this.picBox.firstElementChild)

this.picBox.style.width = this.sliderWidth * this.picBox.children.length + “px”

this.picBox.style.left = -1 * this.sliderWidth + “px”

}

move(offset){

this.animate(offset);

const num = this.indexBox.children[0].children.length

for(let i = 0; i < num; i++){

this.indexBox.children[0].children[i].className = “”

}

this.indexBox.children[0].children[this.index-1].className = “active”

}

animate(offset){

const time = 1000

const rate = 100

let speed = offset / (time/rate)

let goal = parseFloat(this.picBox.style.left) - offset

this.animated = true

let animate = setInterval(() => {

if( this.picBox.style.left == goal || Math.abs(Math.abs(parseFloat(this.picBox.style.left)) - Math.abs(goal)) < Math.abs(speed) ){

this.picBox.style.left == goal

clearInterval(animate)

this.animated = false

if(parseFloat(this.picBox.style.left) == 0){

this.picBox.style.left = -this.sliders * this.sliderWidth + “px”

}else if(parseFloat(this.picBox.style.left) == -(this.sliders+1)*this.sliderWidth){

this.picBox.style.left = -this.sliderWidth + “px”

}

}else{

this.picBox.style.left = parseFloat(this.picBox.style.left) - speed + “px”;

}

}, rate);

}

leftRight(){

this.box.querySelector(“.left-box”).addEventListener(“click”, () => {

//console.log(“left”)

if(this.animated){

return

}

if(this.index - 1 < 1){

this.index = this.sliders

}else{

this.index –

}

this.move(-this.sliderWidth)

})

this.box.querySelector(“.right-box”).addEventListener(“click”, () => {

//console.log(“right”)

if(this.animated){

return

}

if(this.index + 1 > this.sliders){

this.index = 1

}else{

this.index ++

}

this.move(this.sliderWidth)

})

}

play(){

this.auto = setInterval(() => {

this.box.querySelector(“.right-box”).click()

}, 2000);

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

最后的最后

面试题千万不要死记,一定要自己理解,用自己的方式表达出来,在这里预祝各位成功拿下自己心仪的offer。
需要完整面试题的朋友可以点击蓝色字体获取

大厂面试题

面试题目录

/>

最后的最后

面试题千万不要死记,一定要自己理解,用自己的方式表达出来,在这里预祝各位成功拿下自己心仪的offer。
需要完整面试题的朋友可以点击蓝色字体获取

[外链图片转存中…(img-RebL2ZCB-86)]

[外链图片转存中…(img-q8ytgDAd-87)]

[外链图片转存中…(img-2RRFkqY2-87)]

[外链图片转存中…(img-TZpTkdqH-87)]

小讯
上一篇 2025-03-18 09:57
下一篇 2025-01-11 14:28

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/51613.html