-----------------------控制器
public ActionResult Index()
{
return View();
}
public ActionResult GetKill()
{
return View();
}
public ActionResult DingDan()
{
return View();
}
------------------------------------------------------------------------------------
@{
ViewBag.Title = "Kill";
}
<h2>商品秒杀页面</h2>
<script src="~/Scripts/jquery-3.3.1.js"></script>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<div style="800px;height:600px;align-content:center;margin-left:150px">
<div style="float:left;margin-left:100px">
<h4 style="color:red"><b>距离活动结束仅剩:<span id="EndTime"></span><input id="hid" type="hidden" value="75255" /></b></h4>
<img src="~/image/Iphone.png" style="300px;height:430px" alt="" />
</div>
<div style="float:right;margin-top:50px;">
<h3>商品品牌:Iphone</h3>
<h3>商品名称:<span id="Spname"></span></h3><br />
<h4>商品原价:<span id="MarkMoney"></span></h4>
<div style="margin-top:-32px;margin-left:-120px"><hr style="75px;border-bottom:2px solid #5c5c3d;color:black" /></div>
<br />
<h2 style="color:red">秒杀价:<span id="KillMoney"></span></h2><br />
<h4 id="dome1">557*98982用户已经抢到最新版Iphone一台</h4>
<h4>338*98982用户已经抢到最新版Iphone一台</h4>
<h4>999*98982用户已经抢到最新版Iphone一台</h4><br /><br />
<input id="Button1" type="button" class="btn btn-danger" onclick="MiaoKill()" value="立即秒杀" style="250px;height:50px" />
</div>
</div>
<script>
$(function () {
SpShow();
})
function SpShow() {
$.ajax({
url: "http://localhost:51025/api/GetProduct",
type: "get",
DataType: "json",
success: function (i) {
FuDong();
setLeftTime();
$("#Spname").text(i.SPName);
$("#MarkMoney").text(i.MarkPrice);
$("#KillMoney").text(i.KillPrice);
}
})
}
function showSeconds() {
var day1 = Math.floor(seconds / (60 * 60 * 24));
var hour = Math.floor((seconds - day1 * 24 * 60 * 60) / 3600);
var minute = Math.floor((seconds - day1 * 24 * 60 * 60 - hour * 3600) / 60);
var second = Math.floor(seconds - day1 * 24 * 60 * 60 - hour * 3600 - minute * 60);
if (day1 < 0) {
clearInterval(timer);
$("#EndTime").html("已经结束!");
} else {
$("#EndTime").html(day1 + " 天 " + hour + " 小时 " + minute + " 分 " + second + " 秒");
}
seconds--;
}
function setLeftTime() {
seconds = parseInt($("#hid").val(), 10);
timer = setInterval(showSeconds, 1000);
}
function FuDong() {
var $this = $("#dome1");
var scrollTimer;
//事件 鼠标移入停止滚动,移出重置事件,间隔2000毫秒
$this.hover(
function () { clearInterval(scrollTimer); },
function () {
scrollTimer = setInterval(
function () { scrollNews($this); }, 2000);
}).trigger("mouseleave");
//滚动函数,传入div 寻找ul 获得行高,每次上移行高高度,添加行首到末尾
function scrollNews(obj) {
var $self = obj.find("ul");
var lineHeight = $self.find("li:first").height();
$self.animate({ "marginTop": -lineHeight + "px" }, 500, function () {
$self.css("marginTop", "0").find("li:first").appendTo($self);
})
}
}
function MiaoKill() {
alert("秒杀成功!");
location.href = 'Kill/DingDan';
//$.ajax({
// url: "http://localhost:51025/api/GetKill",
// type: "get",
// DataType: "json",
// success: function (i) {
// var r = i.res;
// if (r == 1) {
// alert("秒杀成功!");
// }
// else {
// alert("秒杀失败!");
// }
// }
//})
}
</script>