每个学习页面,在一开始都有这样一个效果,并且是嵌入当前页面的内置的iframe的实际运行效果,而不仅是截图。
根据这样一个截图,学员可以尝试自己完成。
完成不了也没有关系,自己写一遍就会有很多问题,带着这些问题,学习后面的步骤,收获会更大。
");
window.frames["iframe_show3378"].document.write(decodeHtml($("textarea#stepcodeTextarea3378").val()));
window.frames["iframe_show3378"].document.close();
$(window.frames["iframe_show3378"]).load(function(){
$("#iframe_show3378").height($("#iframe_show3378").contents().find("body").height()+showittryitheight);
});
$("#iframe_show3378").height($("#iframe_show3378").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>
</head>
<style>
body{
font-size: 12px;
font-family: Arial;
}
a{
color:#999;
}
.redColor{
color: #C40000 !important;
}
nav.top{
background-color: #f2f2f2;
padding-top: 5px;
padding-bottom: 5px;
border-bottom:1px solid #e7e7e7;
}
nav.top span, nav.top a{
color: #999;
margin: 0px 10px 0px 10px;
}
nav.top a:hover{
color: #C40000;
}
</style>
<nav class="top ">
<a href="#nowhere">
<span class="glyphicon glyphicon-home redColor"></span>
天猫首页
</a>
<span>喵,欢迎来天猫</span>
<a href="#nowhere">请登录</a>
<a href="#nowhere">免费注册</a>
<span class="pull-right">
<a href="forebought">我的订单</a>
<a href="forecart">
<span class=" glyphicon glyphicon-shopping-cart redColor" ></span>
购物车<strong>0</strong>件</a>
</span>
</nav>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>
</head>
<style>
body{
font-size: 12px;
font-family: Arial;
}
a{
color:#999;
}
.redColor{
color: #C40000 !important;
}
nav.top{
background-color: #f2f2f2;
padding-top: 5px;
padding-bottom: 5px;
border-bottom:1px solid #e7e7e7;
}
nav.top span, nav.top a{
color: #999;
margin: 0px 10px 0px 10px;
}
nav.top a:hover{
color: #C40000;
}
</style>
<nav class="top ">
<a href="#nowhere">
<span class="glyphicon glyphicon-home redColor"></span>
天猫首页
</a>
<span>喵,欢迎来天猫</span>
<a href="#nowhere">请登录</a>
<a href="#nowhere">免费注册</a>
<span class="pull-right">
<a href="forebought">我的订单</a>
<a href="forecart">
<span class=" glyphicon glyphicon-shopping-cart redColor" ></span>
购物车<strong>0</strong>件</a>
</span>
</nav>
");
window.frames["iframe3378"].document.write(decodeHtml(code3378));
window.frames["iframe3378"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe3378"]).load(function(){
$("#iframe3378").height($("#iframe3378").contents().find("body").height()+showittryitheight);
});
$("#iframe3378").height($("#iframe3378").contents().find("body").height()+showittryitheight);
alreadyWriteCode3378 = code3378;
$("#rendering3378").hide();
$("#rendered3378").show();
}
var tRereshRetry2DemoPanel3378 = setInterval(rereshRetry2DemoPanel3378,1000);
var binded3378 = false;
$("textarea#stepcodeTextarea3378").keyup(function(){
if(!binded3378){
$(window).bind('beforeunload',function(){
binded3378 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code3378 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code3378!=newCode){
// window.frames["iframe3378"].document.write("
");
// window.frames["iframe3378"].document.write(decodeHtml($("textarea#stepcodeTextarea3378").val()));
// window.frames["iframe3378"].document.close();
// $(window.frames["iframe3378"]).load(function(){
// $("#iframe3378").height($("#iframe3378").contents().find("body").height()+showittryitheight);
// });
// code3378 = newCode;
// }
});
$(".tryButton3378").click(function(){
$("#tryDiv3378").show();
$("#stepcodeTextarea3378").focus();
$("#stepcodeTextarea3378").height(200);
$("#iframe3378").height(0);
window.frames["iframe3378"].document.write("
");
window.frames["iframe3378"].document.write(decodeHtml($("textarea#stepcodeTextarea3378").val()));
window.frames["iframe3378"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe3378"]).load(function(){
$("#iframe3378").height($("#iframe3378").contents().find("body").height()+showittryitheight);
});
$("#iframe3378").height($("#iframe3378").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor3378.focus();
editor3378.setSize(null, "250");
$("#rendering3378").hide();
$("#rendered3378").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor3378 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3378"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor3378.on("change",function(doc){
if(!binded3378){
$(window).bind('beforeunload',function(){
binded3378 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code3378 = newCode;
$("textarea#stepcodeTextarea3378").val(newCode);
if(alreadyWriteCode3378!=code3378){
lastModifedTime3378 = new Date().getTime();
$("#rendering3378").show();
$("#rendered3378").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor3378 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor3378.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv3378").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|