可以自动滚动,或者点左侧箭头上下翻动。(左侧为比特币报价)
套入网页的效果如下
代码如下。主要用到了jquery插件, jQuery News Ticker插件
另:压缩了woff字体并且集成在页面内,所以代码是有点大的。
[PHP] 纯文本查看 复制代码 <?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
function geturl(){
$url = 'https://top.baidu.com/board?tab=realtime';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// $output = json_decode($output,true);
return $output;
}
$content = geturl();
$pattern_neirong = '/<div.*class="c-single-text-ellipsis">(.*)<\/div>.*/isU';
preg_match_all($pattern_neirong, $content, $match_neirong);
$pattern_souvalue = '/<div.*class="hot-index_1Bl1a">(.*)<\/div>.*/isU';
preg_match_all($pattern_souvalue, $content, $match_souvalue);
function float_number($number)
{
$length = strlen($number); //数字长度
if ($length > 10) { //亿单位
$str = substr_replace(floor($number * 0.0000001), '.', -1, 0) . "亿";
} elseif ($length > 6) { //万单位
//截取前俩为
$str = floor($number * 0.001) * 0.1 . "万";
} else {
return $number;
}
return $str;
}
foreach ($match_souvalue[1] as $key => $value) {
$match_souvalue[1][$key] = float_number($value);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style data-for="result" type="text/css" id="css_newi_result">
@font-face {
font-family: cIconfont;
font-weight: 400;
font-style: normal;
src: url('data:font/woff2;charset=utf-8;base64,d09GMgABAAAAAAvUAA0AAAAAG1wAAAt/AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP0ZGVE0cGh4GYACDQhEICqEMmSELOgABNgIkA2wEIAWKQweCIhtPFiMR5oS0kewvDuzGH8+wDyOMcFahZlc9p6yYXhF9I22qpBYn1P8txup30QhJZn8eN+39JEhLoCEBShCvKN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8jEZcXW1MoS228Pzg/C/TS4H2kQQFi0z9UGxR3MjW3BI6DXIi5tL69qtnZaVUtEQogDtyzTPk6UJRHRrLOZ60pU5agdvKCA1Dz3XPZSJp+buRyLV+SsbFFC1W2MpMxcc4VwvT81NtHaA6t5nbN5siXt+Zxrr3PFHbtuqkhSiZg/A9lUFaSreJL0P7Uh2jXwNmia7hxxMl5+j0GYrbpwuUFS81yzgqxh3u3k1J76wQVTzXcjubxPseNkaE88WO16jkoOQIK+as0m5ECMOIeYmmnCSQyTbY37ASVAO9XQ2kF6TMQuuTA2Q8XJ93IaaCJojW/3oWPzQMeQBKqydQinvgTybuVAjX7El2t1D3tzR7sW25gslA1XiIVpiVPTQ9cOAGKlG1wOAQde0ZXsckW8BNF5LMd6wNYa8l7yLjfs4hb2ulwmxXmA23og17Vf1Or35q4mTgNB3MA5CBwGgkchFhLWMEIOghiH0O4ce8F9TFBXIt8P9jvjIVOB937jn2Iz8d7cRLwH1XIAj2THBarl3SJYEqTIkKNAiQo1GrTo0GPAiAlpEY0YpEN6ZEC5yIhYZFKMWLaZLkozkpBUz+dKIpGITBSiEZNYJNbzObJkqrx0XSyQSM/mGroeTzNJoudzLdGrAA==') format('woff2');
}
*{padding:0;margin:0}
.pages{
height: 80px;
width:617px;
font-size: 14px;
color: #9195A3;
}
ul,li{list-style:none}
.left{
position: relative;
float: left;
font-size: 14px;
width: 75px;
height: 60px;
margin:0;
padding-left: 55px;
background-image:url([img]https://image.sinajs.cn/newchart/v8/futures/global/mins/BTC.gif[/img]);
background-size:144px 73px;
}
.srolls{
float: left;
height: 55px;
overflow: hidden;
padding-left: 50px;
width: 360px;
}
.hotwords-side{
position: relative;
width:300px;
height: 11px;
}
.rright{
position: relative;
float: right;
}
.refresh{
position: relative;
float: left;
padding: right;
height: 60px;
margin: 1px 0 0 47px;;
}
.c-icon {
font-family: cIconfont !important;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale
}
.icon-dot, .icon-next, .icon-prev {
font-size: 16px;
height: 18px;
width: 18px;
margin-right: 2px;
color: #4E6EF2;
display: flex;
}
.icon-dot {
margin-left: 5px;
}
a {
font-size: 14px;
font-color: #666;
text-align: left;
margin-top: 2px;
text-decoration-line: none
}
</style>
</head>
<body>
<div class = "pages">
<div class ="left" style="color: #9195A3;" id="nt-BTCPrice" >热搜</div>
<div class="srolls">
<ul id="nt-example1" >
<?php
foreach ($match_neirong[1] as $key => $value) {
$xuhao = ($key + 1);
$souvalue = $match_souvalue[1][$key];
print <<<EOT
<li >
$xuhao
<a target="_blank" title="$value" class="s-wea">$value </a>
<div class="rright">$souvalue<div>
</li>
EOT;
}
?>
</ul>
</div>
<div class="refresh" >
<i id="nt-prev" class="c-icon icon-prev "></i><span>
<i class="c-icon icon-dot "></i><span>
<i id="nt-next" class="c-icon icon-next "></i><span>
</div
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="http://risq.github.io/jquery-advanced-news-ticker/assets/js/jquery.newsTicker.js"></script>
<script>
var nt_example1 = $('#nt-example1').newsTicker({
row_height: 18,
max_rows: 3,
duration: 60000,
prevButton: $('#nt-prev'),
nextButton: $('#nt-next')
});
</script>
<script type="text/javascript">
setInterval(getBTCPrice,10000);
function getLocalTime(time) {
var date = new Date(time*1000 + 8 * 3600*1000 );
return date.toJSON().substr(0, 19).replace('T', ' ');
}
function getBTCPrice(){
$.get( "https://chain.so/api/v2/get_info/BTC", function( response ) {
$("#nt-BTCPrice").empty();
$( "#nt-BTCPrice" )
.append( response.data.price.substr(0, 8) ) ; // current block count
}, "json" );
}
</script>
</body>
</html>
|