首頁 > 其他

jQuery右側懸浮購物車清單效果

2019-12-11 12:39:50

jQuery右側懸浮購物車清單效果

1

新建html文件。


2

準備好需要用到的圖示。



3

書寫hmtl程式碼。

<div class="global_toolbar">

<div class="toolbar_btn center" style="top: 50%; margin-top: -150px;">

<a href="#" id="needtohelp_0_GetPricing" class="bar_forum bar_project_consulting">

<samp>

<i class="iconi icon-LiveChat1">

<img src="img/icon/car-0.png" alt="">

</i>

</samp>

<em>

<i>專案咨詢</i>

</em>

</a>

<a id="needtohelp_0_shoppingCart" class="bar_cart " data-id="global_toolbar">

<samp>

<i class="iconi icon-LiveChat1">

<img src="img/icon/car-1.png" alt="">

</i>

</samp>

<em>

<i>購物車</i>

</em>

<span id="lmliCount" style="display: block;">5</span>

</a>

<a href="#" id="needtohelp_0_forum" class="bar_forum">

<samp>

<i class="iconi icon-LiveChat1">

<img src="img/icon/car-2.png" alt="">

</i>

</samp>

<em>

<i>查詢經銷商</i>

</em>

</a>

<a href="#" id="needtohelp_0_GetQuote" class="bar_forum bar_inquire">

<samp>

<i class="iconi icon-LiveChat1">

<img src="img/icon/car-3.png" alt="">

</i>

</samp>

<em>

<i>售前咨詢</i>

</em>

</a>

<a href="#" id="needtohelp_0_contactus" class="bar_contact bar_forum" data-id="contact_column">

<samp>

<i class="iconi icon-LiveChat1">

<img src="img/icon/car-4.png" alt="">

</i>

</samp>

<em>

<i>更多聯絡方式</i>

</em>

</a>

</div>

<div class="toolbar_content">

<div class="css_column cart_column js_column" id="shop_cart">

<h4>

購物車<a href="javascript:void(0)" class="icon-close " >X</a>

</h4>

<div id="resultData">

<ul style="height: auto;">

<li class="clearfix" data-url="7002728">

<input type="checkbox" class="checkbox_c " name="checkbox_c_Name" data-url="" checked="checked">

<span class="check"></span>

<div class="img_con">

<img src="img/pd/pd1.jpg" alt="">

</div>

<div class="product_name">

<span title="CE12808">CE12808</span>

<a href="javascript:void(0)" class="del_pro_btn" onClick="">刪除</a>

</div>

<div class="amount_btn clearfix">

<input type="text" value="1" class="spinnerExample" onBlur="isDigit(this)">

</div>

</li>

<li class="clearfix" data-url="7002720">

<input type="checkbox" class="checkbox_c" name="checkbox_c_Name" data-url="7002720|" checked="checked">

<span class="check"></span>

<div class="img_con">

<img src="img/pd/pd2.jpg" alt="">

</div>

<div class="product_name">

<span title="CE12804">CE12804</span>

<a href="javascript:void(0)" class="del_pro_btn" onClick="">刪除</a>

</div>

<div class="amount_btn clearfix">

<input type="text" value="9" class="spinnerExample" onBlur="isDigit(this)">

</div>

</li>

<li class="clearfix" data-url="7097193">

<input type="checkbox" class="checkbox_c" name="checkbox_c_Name" data-url="7097193|" checked="checked">

<span class="check"></span>

<div class="img_con">

<img src="img/pd/pd2.jpg" alt="">

</div>

<div class="product_name">

<span title="AR1220EV">AR1220EV</span>

<a href="javascript:void(0)" class="del_pro_btn" onClick="">刪除</a>

</div>

<div class="amount_btn clearfix">

<input type="text" value="1" class="spinnerExample" onBlur="isDigit(this)">

</div>

</li>

<li class="clearfix" data-url="7115213">

<input type="checkbox" class="checkbox_c" name="checkbox_c_Name" data-url="7115213|" checked="checked">

<span class="check"></span>

<div class="img_con">

<img src="img/pd/pd1.jpg" alt="">

</div>

<div class="product_name">

<span title="S5700-28P-PWR-LI-AC">S5700-28...</span>

<a href="javascript:void(0)" class="del_pro_btn" onClick="">刪除</a>

</div>

<div class="amount_btn clearfix">

<input type="text" value="1" class="spinnerExample" onBlur="isDigit(this)">

</div>

</li>

</ul>

</div>

<div class="count_info clearfix">

<label>

<input type="checkbox" class="select_all" checked="checkbox">

<span class="check"></span>

<span class="text">全選</span>

</label>

<p>

共計: <span>12</span>

個產品

</p>

</div>

<div class="more shop-more clearfix">

<a href="#" target="">購買更多產品</a>

</div>

<div class="shop_function_btn clearfix">

<a href="#" class="more redbtn-moddle1" id="btn_popup_login">

<span>登入</span>

</a>

<a href="#" class="go_btn more redbtn-moddle1">

<span>尋求報價</span>

</a>

</div>

</div>

</div>

</div>

<div style="display: none;" class="popup_login">

<div class="login_form">

<a class="close_popup" href="javascript:void(0)">

<img src="img/icon/icon-clo.png" alt="">

</a>

<h3>登入</h3>

<div>

<div class="form_block">

<span class="username_icon input_icon">

<img src="img/icon/user.png" alt="">

</span>

<input type="text" placeholder="帳號/郵箱" maxlength="52" name="userNamepopup" id="userNamepopup">

</div>

<div class="form_block">

<span class="password_icon input_icon">

<img src="img/icon/password.png" alt="">

</span>

<input type="password" placeholder="密碼" maxlength="52" name="pwdpopup" id="pwdpopup">

</div>

<div class="tips_error"></div>

<input type="button" class="form_login_btn" id="btnLoginpopup" value="登入">

</div>

<div class="login_else_info clearfix">

<span>

<a href="#">忘記密碼</a>

<label>|</label>

<a href="#">修改密碼</a>

</span>

<div class="need_reg">

沒有帳號?<a href="#">立即建立一個</a>

</div>

</div>

<div class="other-sign-in-methods"></div>

</div>

<input type="hidden" value="使用者名稱不能為空" id="userNamepopupErrMsg">

<input type="hidden" value="密碼不能為空" id="passwordpopupErrMsg">

</div>


4

書寫css程式碼。

.cistern:after, .clearfix:after { display: table; clear: both; content: " " }

.more.shop-more { float: none; padding: 20px; text-align: center; border-top: 1px solid #e6e6e6; }

.amount_btn { float: right; width: 71px; margin-top: -5px; }

.amount_btn a { float: left; width: 15px; height: 15px; background: #fff; }

.amount_btn input { font-size: 12px; line-height: 12px; float: left; width: 35px; height: 15px; text-align: center; color: #666; border: none; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; }

.count_info { font-size: 12px; position: relative; margin: 20px }

.count_info label { font-size: 14px; float: left; width: 70px; color: #666; }

.count_info label input { width: 15px; margin-right: 10px; cursor: pointer; }

.count_info label span.text { display: inline-block; cursor: pointer; }

.count_info p { font-size: 14px; float: right; width: 70%; margin: 0; text-align: right; color: #666; }

.shop_function_btn { padding: 20px 0; text-align: center; border-top: 1px solid #e6e6e6; border-bottom: 1px solid #e6e6e6 }

.shop_function_btn a { margin: 0 10px }

div.more { line-height: 1.1; float: right; clear: both; margin-top: 12px; padding-left: 0!important }

.more-resources .more a, .more a { display: inline-block; padding-left: 20px; color: #999 }

.more-resources label { display: inline-block; margin-bottom: 12px; -webkit-transition: all .4s cubic-bezier(.2, .83, .42, .91); transition: all .4s cubic-bezier(.2, .83, .42, .91); vertical-align: top }

.more a:hover { text-decoration: underline; color: #333 }

.more a em, .more a i { font-size: 24px; font-style: normal; display: inline-block; width: 36px; height: 23px; margin-left: -12px; color: #e50000; -webkit-font-smoothing: antialiased }

.more a em:before, .more a i:before { position: relative; top: 3px; }

.cloud_computing div.more { float: none }

.global_toolbar.default { position: absolute }

.global_toolbar.default .toolbar_content, .global_toolbar.opacity .toolbar_content { display: none }

.global_toolbar.opacity .toolbar_btn a em, .global_toolbar.opacity .toolbar_btn a samp { background: #000; background: rgba(0,0,0,.8); cursor: pointer }

.global_toolbar.opacity .toolbar_btn a:hover em { background: #e50000 }

.global_toolbar { position: fixed; z-index: 1001; top: 0; right: 0; width: 0; height: 100%; -webkit-transition: all .4s cubic-bezier(.2, .83, .42, .91); transition: all .4s cubic-bezier(.2, .83, .42, .91); border-left: 1px solid #d0d0d0; background: #fff }

.global_toolbar.open { width: 320px }

.wap_cartbtn { display: none }

.toolbar_btn { position: absolute; top: 100%; left: -60px; width: 60px }

.toolbar_btn a, .toolbar_btn a samp { position: relative; display: block; height: 60px; -webkit-transition: all .4s cubic-bezier(.2, .83, .42, .91); transition: all .4s cubic-bezier(.2, .83, .42, .91); border-bottom: 1px solid #37393d }

.toolbar_btn a samp { z-index: 2; width: 60px; color: #fff; background-color: #000 }

.toolbar_btn a samp .iconfont { font-size: 24px; position: absolute; top: 16px; left: 18px; color: #fff }

.toolbar_btn a em { font-size: 16px; font-style: normal; line-height: 60px; position: absolute; z-index: 1; top: 0; right: 60px; display: block; overflow: hidden; width: 0; height: 60px; -webkit-transition: all .4s cubic-bezier(.2, .83, .42, .91); transition: all .4s cubic-bezier(.2, .83, .42, .91); text-align: center; color: #fff; background-color: #000 }

.LANG-cn .toolbar_btn a font { width: 160px }

.toolbar_btn a font { display: block; width: 180px; padding: 0 30px; text-align: left; white-space: nowrap; word-break: keep-all }

.toolbar_btn a.current samp, .toolbar_btn a:hover samp { border-bottom: 1px solid #e50000; background-color: #e50000; }

.toolbar_btn.default a:hover samp { background-color: #e50000 }

.LANG-cn .toolbar_btn a:hover em { width: 160px }

.toolbar_btn a:hover em { width: 180px; background: #e50000 }

.toolbar_btn a span { font-size: 10px; line-height: 11px; position: absolute; z-index: 3; top: 10px; right: 10px; display: none; overflow: hidden; min-width: 11px; height: 14px; padding: 1px 2px; text-align: center; color: #fff; border: 1px solid #e50000; border-radius: 10px; background: #e50000 }

.toolbar_btn a.current span, .toolbar_btn a:hover span { color: #e50000; background: #fff }

.LANG-cn .toolbar_btn.default em { width: 160px }

.toolbar_btn.default em { width: 180px }

.toolbar_btn.default a samp, .toolbar_btn.default em { border-bottom: 1px solid #37393d; background: #000 }

.toolbar_content { z-index: 3; width: 100% }

.css_column, .toolbar_content { position: absolute; top: 0; left: 0; height: 100% }

.css_column { z-index: 1000; overflow: hidden; width: 320px; min-width: 280px; background: #fafafa }

.css_column h4 { font-size: 24px; position: relative; margin: 0; padding: 15px 20px; color: #666; border-bottom: 1px solid #e6e6e6; background: #fff; font-weight: normal; }

.css_column h4 a { font-size: 20px; position: absolute; top: 19px; right: 10px; display: block; width: 20px; height: 20px; color: #bfbfbf; }

.css_column h4 a:hover { color: #e50000 }

.cart_column ul { overflow: auto; padding: 0 20px; border-bottom: 1px solid #e6e6e6 }

#resultData { overflow: auto }

.cart_column li { position: relative; padding: 20px 0; border-bottom: 1px solid #e6e6e6 }

.cart_column li:last-child { border: none }

.cart_column li .img_con { float: left; width: 70px; margin: 0 10px 0 38px; text-align: center; }

.cart_column li .checkbox_c { float: left; width: 15px; margin-top: 20px; position: absolute; z-index: 2; opacity: 0; left: 0; cursor: pointer; }

.cart_column li .checkbox_c:checked+span { background: #fff }

.cart_column li .check { position: absolute; top: 36px; left: 0; display: none9; width: 20px; height: 20px; }

.cart_column li img { width: 100% }

.cart_column li .product_name { font-size: 12px; line-height: 16px; float: left; width: 100px; margin-right: 10px; }

.cart_column li .product_name span { font-size: 16px; display: block; margin-bottom: 3px; padding-top: 8px; cursor: pointer; color: #666 }

.cart_column li .product_name a { font-size: 14px; line-height: 16px; color: #999 }

.cart_column li .product_name a:hover { color: #0166fe }

.compare_column ul { margin-bottom: 20px }

.compare_column li .img_con { margin: 0 10px 0 0 }

.compare_column li.null { min-height: 73px; padding: 20px 0; }

.contact_column ul { margin-top: 30px }

.contact_column li { margin-bottom: 20px }

.contact_column li a { display: block; min-height: 50px; text-decoration: none }

.contact_column li a:hover img { opacity: .8 }

.contact_column li h3 { font-size: 16px; font-weight: 400; line-height: 1.5; margin: 0 0 8px; color: #333 }

.contact_column li p { font-size: 12px; line-height: 14px; margin: 0; color: #666 }

.contact_column li a:hover h3, .contact_column li a:hover p { color: #0166fe }

.contact_tel { padding: 14px 0; border-top: 1px solid #d7d7d7; border-bottom: 1px solid #d7d7d7 }

.contact_tel span { font-size: 24px; line-height: 50px; display: block; min-height: 50px; color: #787878 }

.else_contact { margin: 10px 0 0; text-align: right }

.else_contact a { font-size: 14px; color: #333 }

.else_contact a:hover { color: #0166fe }

.listimg_wrap { float: left; width: 18% }

.redbtn-moddle1 { font-size: 14px; line-height: 1.2; position: relative; display: inline-block; overflow: hidden; padding: 16px 30px; -webkit-transition: all .5s; transition: all .5s; text-transform: capitalize; color: #fff; background: #e50000 }

.redbtn-moddle1:hover { color: #fff }

.redbtn-moddle1:before { position: absolute; z-index: 0; top: 0; left: -100%; display: block; width: 100%; height: 100%; content: ""; -webkit-transition: all .4s ease-in-out; transition: all .4s ease-in-out; background: #b20000 }

.redbtn-moddle1:hover:before { left: 0 }

.redbtn-moddle1 span { font-size: 16px; position: relative; z-index: 1; letter-spacing: 1px }

:root .popup_login { background-color: rgba(0,0,0,.5); }

.login_form { background: #fbfcfc; }

.login_form { width: 60%; float: left; background: #fff; border-top-right-radius: 5px; border-bottom-right-radius: 5px; padding: 50px 77px 120px; position: relative; }

.popup_login { position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 1005; background: url("/themes/img/icon/alpha60.png") repeat; }

.login_form h3 { font-size: 26px; margin-bottom: 30px; font-weight: normal; }

.popup_login .login_form { padding-bottom: 40px; z-index: 1006; margin: 0 auto; float: none; width: 480px; border-radius: 0; position: fixed; left: 50%; margin-left: -240px; top: 50%; margin-top: -200px; padding-left: 38px; padding-right: 38px }

.close_popup { display: block; width: 22px; height: 22px; position: absolute; top: 15px; right: 20px; }

.close_popup img { width: 100%; height: auto; display: block; border: none; }

.form_block { border: 1px #d4d4d4 solid; height: 48px; padding-left: 50px; position: relative; margin-bottom: 18px; }

.input_icon { display: block; position: absolute; width: 16px; height: 16px; left: 15px; top: 16px; }

.username_icon img { width: 100%; height: auto; display: block; border: none; }

.password_icon img { width: 100%; height: auto; display: block; border: none; }

.form_block input { border: none; height: 46px; line-height: 46px; font-size: 14px; width: 100%; padding: 0 10px 0 0; -webkit-outline: none; outline: none; }

.form_login_btn { width: 100%; height: 50px; line-height: 43px; text-align: center; border: none; background: #ff3c5b; color: #fff; font-size: 18px; }

.form_login_btn:hover { background: #d70226 }

.form_login_btn.disabled { background: #ccc; color: #e7e7e7; }

.login_else_info { margin-top: 10px; }

.login_else_info span { float: left; font-size: 14px; }

.login_else_info span label { display: inline-block; margin: 0 10px; color: #adadad; }

.login_else_info span a { color: #333; }

.need_reg { float: right; font-size: 12px; color: #666; }

.need_reg a { font-size: 14px; color: #ff3c5b; font-weight: bold; }

.login_else_info a:hover { color: #0166FE }

.tips_error { text-align: center; color: #e50000; font-size: 14px; margin-bottom: 15px; }

.toolbar_btn a em i { font-style: normal; }

.iconi { width: 30px; height: 30px; display: block; position: absolute; top: 15px; left: 15px; }

.icon-LiveChat1 img { width: 100%; height: auto; display: block; border: none; }

.icon-close { position: absolute; right: 0; }

.spinner { height: 25px; width: 71px; overflow: hidden;  *zoom:1;

-webkit-box-shadow: 0 3px 3px -4px #aaa; -moz-box-shadow: 0 3px 3px -4px #aaa; box-shadow: 0 3px 3px -4px #aaa }

.spinner button, .spinner .value { text-align: center; display: block; float: left; height: 100%; line-height: 20px; margin: 0; }

.spinner button { border: none; width: 23px; color: #e5312a; font: 22px Arial bold; padding: 0; outline: none; }

.spinner .decrease { background-position: 0 -50px; cursor: pointer; text-indent: -10000px }

.spinner .decrease[disabled] { background-position: 0 -75px; cursor: default }

.spinner .increase { background-position: 0 0; cursor: pointer; text-indent: -10000px; }

.spinner .value { background-position: 0 -100px; width: 24px; height: 25px; border: none; color: #000; padding: 0; }

.spinner .value.passive { background-position: 0 -25px; color: #919191 }

.spinner .error, .spinner .invalid { background: #aa0000 }


5

書寫並新增js程式碼。

function openCart() {

    var t = $(window).width();

    0 == $(".shopping_all").length ? t > 768 ? $("#shop_cart").animate({

        right: 35

    }, 300) : $("#shop_cart").animate({

        right: 0

    }, 300) : t > 980 ? $("#shop_cart").animate({

        right: 35

    }, 300) : $("#shop_cart").animate({

        right: 0

    }, 300),

    $(".compare_btn").hasClass("open") && closeCompare(),

        $(".shop_cart").addClass("bg")

}

function openBar() {

    toolbar.hasClass("open") || (toolbar.addClass("open"),

        $("#shop_cart .lazyload").removeClass("hidden").find("img").trigger("appear"),

        $(".global_toolbar").removeClass("default"),

        $(".toolbar_btn").css({

            top: "50%",

            marginTop: -$(".toolbar_btn").height() / 2

        })),

        $(".global_toolbar").removeClass("opacity"),

        $(".toolbar_btn").removeClass("default")

}

function closeBar() {

    $(".toolbar_btn a").removeClass("current"),

        toolbar.removeClass("open"),

        $(".toolbar_btn").removeClass("default")

}

function openCartMeiu() {

    var t = $(window).width();

    $(".bar_cart").hasClass("current") || $(".bar_cart").addClass("current").siblings("a").removeClass("current"),

        $(".global_toolbar").hasClass("open") ? closeBar() : openBar(),

        t > 768 ? $(".bar_cart").hasClass("current") || $(".bar_cart").trigger("click") : openBar()

}


6

程式碼整體結構。


7

檢視效果。



IT145.com E-mail:sddin#qq.com