【发布时间】:2012-08-05 12:25:42
【问题描述】:
我整天都在寻找这个,但我自己无法弄清楚..
我有一个购物车,您可以在其中添加商品。购物车位于下拉列表中,因此您必须单击它才能查看它。因此,每次您将商品添加到购物车时,我都想在某处显示“+1”、“+2”等,当您单击下拉菜单时,它会消失,因此它可以重新开始计数。 所以,我认为当 div 的高度发生变化时,它可以显示 +1。
但是,我不知道足够的 javascript 来做到这一点......
我的html:
<div id="button">Button</div>
<div id="chartdropupcontainer">
<div id="chart">
<button>test</button>
<script type="text/javascript">
$("button").click(function () {
$("#testp").hide();
});
$("#chart").bind("resize", function(){
alert("test");
});
</script>
<p id="testp"></p>
</div>
</div>
</div>
我的 CSS:
* {
padding: 0;
margin: 0;
font-family: Helvetica;
color: white;
}
#chartdropupcontainer {
width: 200px;
background-color: red;
position: fixed;
bottom: 0;
right: 0;
margin-right: 20px;
padding: 0 5px 0 5px;
margin-bottom: 47px;
z-index: 998;
}
#chartdropupcontainer h1 {
margin: 5px;
color: black;
cursor: pointer;
}
#chart {
width: 100%;
background-color: black;
height: 400px;
overflow: auto;
}
#button {
background-color: blue;
cursor: pointer;
padding: 10px;
width: 190px;
position: fixed;
bottom: 0;
right: 0;
margin-right: 20px;
z-index: 999;
}
我的javascript:
$(document).ready(function() {
$("#button").click(function () {
$("#chartdropupcontainer").slideToggle("slow");
});
});
这里是一个在线版本的链接:http://www.rutgerinc.nl/niels/
编辑:对不起,有点不礼貌! 谁能帮我解决这个问题?
【问题讨论】:
-
你不能把它挂在添加商品到购物车的方法中吗?或者让购物车对象在添加商品时触发一个事件。让它依赖于 html 标签的维度属性似乎有点奇怪和不稳定。
-
我真的不会依赖表示更改来表示应用程序状态的更改。例如,如果用户增加了字体大小,您可能会看到触发了相同的事件。我真的建议要么将此业务逻辑拉入您的服务器脚本(您可能更舒服)或构建一些代码来处理用户交互。购物车是您不想在其中出错的应用程序。
标签: javascript jquery css html height