HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<script src="https://apps.bdimg.com/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
<div class="box">
<div class="content">
<h1 style="font-size: 20px;text-align: center;padding: 10px 0">马刺主场大胜灰熊2-0 莱纳德13分邓肯3分9篮板</h1>
<p>
网易体育4月20日报道:<br> 圣安东尼奥马刺队在主场扩大优势。米尔斯替补得到16分,莱纳德得到13分,他们带领球队4人得分上双,马刺队在比赛中逐渐发力拉开比分,他们在西部首轮系列赛第二战主场以94-68战胜孟菲斯灰熊队。马刺队把总比分扩大为2-0,双方的第三场将移师孟菲斯进行。
</p>
<img src="http://img3.cache.netease.com/photo/0005/2016-04-20/BL3G2K6J4TM10005.jpg">
<p>
马刺队的米尔斯得到16分,莱纳德得到13分,阿尔德里奇得到10分、8个篮板和4次盖帽,马丁得到10分,邓肯得到3分、9个篮板和4次助攻。灰熊队的阿伦得到12分和3个篮板,兰多夫得到11分和12个篮板,巴恩斯得到9分和6个篮板。
</p>
<p>
支球队开赛后争夺激烈,场上比分交替增加,马丁两罚一中,首节还有2分55秒时灰熊队以11-13落后。之后的比赛被马刺队掌控,吉诺比利连投带罚得到4分,米尔斯三分中的,他们带领球队打出9-0的小高潮,马刺队以22-11领先11分结束首节。
</p>
<p>
阿伦独得4分,他率队在第二节打出8-2的反击波,灰熊队追至21-27。米尔斯挺身而出还击5分,莱纳德、马丁等人轮流得分,半场前3分40秒时马刺队以41-24领先17分。巴恩斯跳投命中,马丁三分命中,帕克跳投得分,马刺队在半场结束时以49-35领先14分。
</p>
<p>
马刺队的莱纳德上半场得到9分,米尔斯得到8分;灰熊队的阿伦得到8分,兰多夫得到7分和6个篮板。
</p>
<p>
第三节开始后不久阿尔德里奇两次跳投命中,吉诺比利两罚一中,马刺队以63-45领先18分。阿伦连投带罚拿下4分帮助球队追分,米尔斯再中三分,邓肯两罚一中,马刺队在三节结束时以70-53领先。
</p>
<p>
安德森连续罚进四球开启第四节,马刺队领先21分。灰熊队打得很顽强,兰多夫独得4分,法玛尔跳投命中,他们帮助球队缩小差距。马刺队的两位老将这时找到准星,他们为球队确立胜局。韦斯特突破扣篮,马丁投中三分,他们各得4分率队打出8-2的攻击波,第四节还有3分15秒时马刺队以88-63领先25分。大比分差距让比赛提前失去悬念,双方都尽遣替补,马刺队以94-68获胜。
</p>
<p>灰熊队首发阵容:法玛尔、卡特、巴恩斯、兰多夫、安德森</p>
<p>马刺队首发阵容:帕克、格林、莱纳德、阿尔德里奇、邓肯</p>
</div>
</div>
*{padding:0;margin:0;font:14px/1.8 "microsoft yahei";-moz-user-select:none;/**禁止选中文字*/}
.box{width:600px;height:600px;position:relative;border:1px solid #d9d9d9;margin:0 auto;overflow:hidden; margin-top: 200px;}
.content{padding:10px;word-break:break-all;}
p{margin-bottom:10px;text-indent:2em;}
p+img{max-width:100%;margin:10px auto;display:block;}
(function($) {
$.fn.scrollBar = function(options) {
var defaults = {
foregroundColor: 'red',
backgroundColor: '#d5d5d5',
height: 400,
width: 600,
sliderBoxWidth: 10,
sliderBarHeight: 100,
mousewheel: true,
radius: 5,
scrollDirection: "y",
}
var obj = $.extend(defaults, options);
this.each(function(index, el) {
var me = $(this);
var content = me.children().eq(0);
var isMouseDown = false;
var distance = 0;
me.css({
height: obj.height,
position: 'relative',
width: obj.width,
});
content.css("padding", 10)
if (me.outerHeight() < content.outerHeight() || me.outerWidth() < content.outerWidth()) {
var slider = "<div class='slider'><span></span></div>";
me.append(slider);
};
if (slider) {
var sliderBox = me.find(".slider"),
sliderBar = sliderBox.find("span");
// 如果是纵向滚动;
if (obj.scrollDirection.toLowerCase() === "y") {
var BarHeight = me.outerHeight() / content.outerHeight() * obj.sliderBarHeight;
me.css("paddingRight", content.css("paddingLeft"));
sliderBox.css({
position: 'absolute',
top: 2,
right: 2,
width: obj.sliderBoxWidth,
height: obj.height - 4,
background: obj.backgroundColor,
borderRadius: obj.radius,
overflow: 'hidden'
});
sliderBar.css({
position: 'absolute',
top: 0,
right: 0,
width: obj.sliderBoxWidth,
background: obj.foregroundColor,
height: BarHeight,
});
sliderBar.on("mousedown", function(event) {
event.preventDefault();
isMouseDown = true;
});
$(window).on('mousemove', function(event) {
event.preventDefault();
distance = event.pageY - me.offset().top
if (isMouseDown == true) {
scrollY(distance)
}
});
$(window).on('mouseup', function() {
isMouseDown = false;
});
// 鼠标滚轮事件;
if (obj.mousewheel) {
me.bind("mousewheel", function(event, delta) {
distance = sliderBar.offset().top - me.offset().top;
delta > 0 ? distance -= 10 : distance += 10;
scrollY(distance);
})
}
function scrollY(distance) {
if (distance < 0) {
distance = 0
} else if (distance > sliderBox.outerHeight() - sliderBar.outerHeight()) {
distance = sliderBox.outerHeight() - sliderBar.outerHeight();
}
sliderBar.css("top", distance);
var scale = distance / (sliderBox.outerHeight() - sliderBar.outerHeight())
var scrollDistance = parseInt(scale * (content.outerHeight() - me.outerHeight()));
content.css("marginTop", -scrollDistance)
}
}
// 如果是横向滚动;
if (obj.scrollDirection.toLowerCase() === "x") {
content.css("width", content.outerWidth() * 2);
me.css("height", "auto")
var BarWidth = me.outerWidth() / content.outerWidth() * obj.sliderBarHeight;
me.css("paddingBottom", content.css("paddingLeft"));
sliderBox.css({
position: 'absolute',
left: 2,
bottom: 2,
width: obj.width - 4,
height: obj.sliderBoxWidth,
background: obj.backgroundColor,
borderRadius: obj.radius,
overflow: 'hidden'
});
sliderBar.css({
position: 'absolute',
left: 0,
bottom: 0,
width: BarWidth,
background: obj.foregroundColor,
height: obj.sliderBoxWidth,
});
sliderBar.on("mousedown", function(event) {
event.preventDefault();
isMouseDown = true;
});
$(window).on('mousemove', function(event) {
event.preventDefault();
distance = event.pageX - me.offset().left
if (isMouseDown == true) {
scrollX(distance)
}
});
$(window).on('mouseup', function() {
isMouseDown = false;
});
// 鼠标滚轮事件;
if (obj.mousewheel) {
me.bind("mousewheel", function(event, delta) {
distance = sliderBar.offset().left - me.offset().left;
delta > 0 ? distance -= 10 : distance += 10;
scrollX(distance);
})
}
function scrollX(distance) {
if (distance < 0) {
distance = 0
} else if (distance > sliderBox.outerWidth() - sliderBar.outerWidth()) {
distance = sliderBox.outerWidth() - sliderBar.outerWidth();
}
sliderBar.css("left", distance);
var scale = distance / (sliderBox.outerWidth() - sliderBar.outerWidth())
var scrollDistance = parseInt(scale * (content.outerWidth() - me.outerWidth()));
content.css("marginLeft", -scrollDistance)
}
}
}
});
}
})(jQuery)
$('.box').scrollBar({
height: 600,
scrollDirection:"y",
})
Also see: Tab Triggers