请教购物车下拉菜单的问题

请教购物车下拉菜单的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="css/base.css"/>
    <link rel="stylesheet" href="css/common.css"/>
    <link rel="stylesheet" href="css/index.css"/>
</head>
<body>
<!-- 购物车 -->
            <div class="cart dropdown fl" data-active="cart" data-load="js/dropdown-seller.json">
                <a href="###" target="_blank" class="dropdown-toggle link transition">
                    <i class="cart-car icon margin">&#xe609;</i>
                    <span class="cart-word margin">购物车</span>
                    <span class="cart-vline margin">|</span>
                    <span class="cart-count margin">20</span>
                    <i class="dropdown-arrow icon transition">&#xe609;</i>
                </a>
 
            <!-- 要完美还原 要重新设计html结构,外层再用一个div -->
                <ul class="dropdown-layer dropdown-commodity">
                    <!-- <li>
                        <div class="dropdown-none cf">
                        <div class="dropdown-none-1 fl">img</div>
                        <div class="dropdown-none-2 fl"> 购物车里还没有商品,赶紧去选购吧!</div> 
                        </div>
                    </li> -->
                    <li class="dropdown-loading"></li>
                    <!-- <li class="title cart-item">最近加入的商品</li>
                    <li>
                        <a href="###" target="_blank" class="cart-item">
                            <div class="cart-item-cotent cf">
                                <div class="cart-item-cotent-img fl">
                                    <img src="img/cart/1.png">
                                </div>
                                <div class="cart-item-cotent-word fl">
                                    <p class="cart-item-cotent-intro linht">adidas 阿迪达斯</p>
                                    <p class="cart-item-cotent-price linht">¥335*1</p>
                                </div>
                                <i class="dropdown-arrow icon fl cart-item-cotent-icon linht">
                                    &#xe609;
                                </i>
                            </div>
                        </a>
                    </li>
                    <li class="cart-item-last">
                        <span class="total">共<b>0</b>件商品 共计<b>¥ 0.00</b></span> 
                        <a href="###" class="gocart">去购物车</a>
                    </li> -->
                </ul>
            </div>
 
    <script>
        //两种判断是否有jquery库的写法:
        // window.jQuery || document.write('<script src="js/jquery.js"><' + '/script>')
        window.jQuery || document.write('<script src="js/jquery.js"><\/script>');
    </script>
    <script src="js/transition.js"></script>
    <script src="js/showhide.js"></script>
    <script src="js/dropdown.js"></script>
    <script src="js/index.js"></script>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*下拉菜单样式dropdown*/
.cart{
    background-color#f01414;
    width180px;
    height50px;
    top100px;
    left50%;
    margin-left-90px;
    line-height50px;
    font-size16px;
}
 
.cart a{
    color#f3f5f7;
}
 
.margin{
    margin5px;
}
 
.cart-car{
    width20px;
    height18px;
}
 
.cart-count{
    margin-right0;
}
 
/*.cart .dropdown*/
.cart .dropdown-toggle {
    displayblock;
    height100%;
    padding0 13px 0 12px;
}
 
 
.cart-item {
    displayblock;
    height80px;
    color#4d555d!important;
    margin0 12px;
    border-bottom1px solid #cdd0d4;
}
 
/* -active样式 */
.cart-active,
.cart-active .dropdown-layer{
    box-shadow: 0 0 5px rgba(000, .2);
}
/* 购物车 */
.cart-active .dropdown-toggle {
    background-color#fff;
}
.dropdown-layer{
    displaynone;
    width400px;
    top49px;
    left-222px;
    background-color#fff;
    border1px solid #cdd0d4;
}
 
/* 模拟加载 */
.dropdown-loading{
    margin34px auto;
}
/* 无商品 */
.dropdown-none{
    width200px;
    margin34px auto;
}
.dropdown-none-1{
    width50px;
    height50px;   
}
.dropdown-none-2{
    line-height20px;
    width150px;
    color#cdd0d4;
}
 
/* 有商品 */
.cart-active .dropdown-commodity{
    width400px;
    border-bottom1px solid #cdd0d4;
    overflowauto;
}
 
.cart-active .dropdown-commodity li:last-child .cart-item{
    border-bottom:none;
}
 
.cart-item-cotent{
    padding15px 10px;
    positionrelative;
}
 
.cart-item-cotent-word{
    margin-left20px;
}
.linht{
    height25px;
    line-height25px;
}
 
.cart-item-cotent-price{
    font-weightbold;
     
}
.cart-item-cotent-icon{
    positionabsolute;
    right0;
     
}
 
.title{
    height50px;
    text-indent18px;
    font-weightbold;
}
.total{
    line-height80px;
    margin-left30px;
}
.cart-item-last{
    positionrelative;
}
.gocart{
    display: inline-block;
    width100px;
    height50px;
    positionabsolute;
    top50%;
    right12px;
    margin-top-25px;
    background-color#f01414;
    color#fff;
    border-radius: 5px;
    text-aligncenter;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function ($) {
 
$(".dropdown").dropdown({
        css3: true,
        js: false
         
});
// 从本地数据库获取json数据
$('.dropdown').on('dropdown-show'function (e) {
            var $this = $(this),
                dataLoad = $this.data('load');
                
            if (!dataLoad) return;
 
            if (!$this.data('loaded')) {
 
                var $layer = $this.find('.dropdown-layer'),
                    html = '';
 
                $.getJSON(dataLoad, function (data) {
                    console.log(data);
                    var len = data.length - 1;
                    if(len < 0){
                        html = '<li><div class="dropdown-none cf"><div class="dropdown-none-1 fl">img</div><div class="dropdown-none-2 fl"> 购物车里还没有商品,赶紧去选购吧!</div></div></li>';
                        $layer.html(html);
                        $this.data('loaded'false);
                    }else{
                        // html = '<li class="dropdown-loading"></li>';
                        setTimeout(function () {
                            html = '<li class="title cart-item">' + data[0].title + '</li>';
                            for (var i = 1; i < len; i++) {
                                // html += '<li><a href="' + data[i].url + '" target="_blank" class="cart-item">' + data[i].name + '</a></li>'
                                html +='<li><a href="' + data[i].url + '" target="_blank" class="cart-item"><div class="cart-item-cotent cf"><div class="cart-item-cotent-img fl"><img src="' + data[i].img + '"></div><div class="cart-item-cotent-word fl"><p class="cart-item-cotent-intro linht">' + data[i].intro + '</p><p class="cart-item-cotent-price linht">' + data[i].price + '</p></div><i class="dropdown-arrow icon fl cart-item-cotent-icon linht"> ' + data[i].icon + '</i></div></a></li>'
                            }
 
                        html = html + '<li class="cart-item-last"><span class="total">' + data[len].total + '<b>' + data[len].price + '</b></span> <a href="###" class="gocart">' + data[len].cart + '</a></li>';
 
                            $layer.html(html);
                            $this.data('loaded'true);
                        }, 3000);
                    }
                });
            }
        });
})(jQuery);

[

    {

        "title": "最近加入商品"

    },

    {

        "url": "###",

        "img": "img/cart/1.png",

        "intro": "adidas 阿迪达斯111",

        "price": "¥335*1",

        "icon": "&#xe609;"

    },

    {

        "url": "###",

        "img": "img/cart/2.png",

        "intro": "adidas 阿迪达斯2222",

        "price": "¥335*2",

        "icon": "&#xe609;"

    },

    {

        "url": "###",

        "img": "img/cart/3.png",

        "intro": "adidas 阿迪达斯3333333",

        "price": "¥335*3",

        "icon": "&#xe609;"

    },

    {

        "url": "###",

        "img": "img/cart/4.png",

        "intro": "adidas 阿迪达斯44444",

        "price": "¥335*4",

        "icon": "&#xe609;"

    },

    {

        "url": "###",

        "img": "img/cart/5.png",

        "intro": "adidas 阿迪达斯5555555",

        "price": "¥335*5",

        "icon": "&#xe609;"

    },

    {

        "total": "共0件商品  共计  ",

        "price": "¥ 0.00",

        "cart": "去购物车"

    }

]

1、请老师帮我优化一下代码,谢谢。

2、本地服务器怎么设置啊,有教程吗?

3、那个<li class="dropdown-loading"></li>, dropdown-loading是在js中哪里加载的,我找不到。


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕星星 2019-10-12 14:17:54

你好,

辅助资料里面就有购物车商品图片哦:

http://img1.sycdn.imooc.com//climg/5da16fcd09d70fa103050095.jpg

http://img1.sycdn.imooc.com//climg/5da16fd909fddd3604690213.jpg

同学说的购物车和关闭的图片文字,还有购物车的图片在哪里?老师不太明白的你的意思,建议描述具体一些,便于准确定位问题,高效为你解决。

祝学习愉快

好帮手慕星星 2019-10-12 11:07:00

同学你好,

1、代码实现效果不错,不需要修改了哦。

2、可以用wampserver服务器进行测试,在jquery中ajax课程中有讲解过,还有资料文档,可以看一下:

http://img1.sycdn.imooc.com//climg/5da1426609e6a23f13270851.jpg

3、加载图片在html结构中是显示的,不是在js中加载的:

http://img1.sycdn.imooc.com//climg/5da142970952d0b906840294.jpg

视频中css/common.css文件中进行了设置:

http://img1.sycdn.imooc.com//climg/5da143480986f22406450161.jpg

自己可以再测试下,祝学习愉快!

欢迎采纳~

  • 购物车和关闭的图片文字,还有购物车的图片在哪里?img中没找到,能跟我说一下怎么设置吗?
    2019-10-12 11:42:41
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
2.组件化网页开发
  • 参与学习           人
  • 提交作业       1121    份
  • 解答问题       14456    个

本阶段在运用JS实现动态网页开发的基础上,带你深入理解企业开发核心思想,完成一个企业级网页的开发,体验前端工程师的成就感。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码