You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
7.4 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web新闻网站</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="Progress">
<div class="Prostick"></div>
</div>
<div class="navbar">
<div class="navbar-left">
<img src="logo.png" alt="Logo">
<div class="site-title">Web新闻网站</div>
</div>
<div class="navbar-right">
<a href="#" class="active">首页</a>
<a href="#">新闻分类</a>
<a href="#">专题报道</a>
<a href="#">新闻资讯</a>
<a href="#">互动交流</a>
<div class="line"></div>
</div>
</div>
<div class="carousel-container">
<div class="carousel-images">
</div>
<button id="prev-btn"></button>
<button id="next-btn"></button>
<div class="dots-container">
</div>
</div>
<div class="news-effect">
<span>新闻的作用</span>
<div class="news-class-list">
<p>1.消除受众的不确定性。新闻通过报道新发生的事件和情况,帮助受众了解世界的最新变化。</p>
<p>2.新闻能够反映社会现象和问题,影响和引导公众的思想和行为,实现社会舆论的监督引导。</p>
<p>3.新闻报道涉及广泛的科学技术和社会生活领域,有助于人们获取新知识和新发现教育普及。</p>
<p>4.新闻媒介还传播各种趣味性内容,如奇闻异事、风土人情等,在紧张工作得到娱乐和享受。</p>
</div>
</div>
<div class="news-definition">
<p>“新闻,也叫消息、资讯,是通过报纸、电台、广播、电视台等媒体途径所传播信息的一种称谓。是记录社会、传播信息、反映时代的一种文体。新闻概念有广义与狭义之分,就其广义而言,除了发表于报刊、广播、互联网、电视上的评论与专文外的常用文本都属于新闻之列,包括消息、通讯、特写、速写(有的将速写纳入特写之列)等等,狭义的新闻则专指消息,消息是用概括的叙述方式,比较简明扼要的文字,迅速及时地报道国内外新近发生的、有价值的事实,让别人了解”。
</p>
</div>
<div class="news-definition">
<p>“新闻,也叫消息、资讯,是通过报纸、电台、广播、电视台等媒体途径所传播信息的一种称谓。是记录社会、传播信息、反映时代的一种文体。新闻概念有广义与狭义之分,就其广义而言,除了发表于报刊、广播、互联网、电视上的评论与专文外的常用文本都属于新闻之列,包括消息、通讯、特写、速写(有的将速写纳入特写之列)等等,狭义的新闻则专指消息,消息是用概括的叙述方式,比较简明扼要的文字,迅速及时地报道国内外新近发生的、有价值的事实,让别人了解”。
</p>
</div>
<div class="news-elevator">
<ul class="news-elevator-list">
<li><a href="#"></a>新鲜好物</li>
<li><a href="#"></a>人气推荐</li>
<li><a href="#">热门品牌</a></li>
<li><a href="#">最新专题</a></li>
<li><a href="#">顶部</a></li>
</ul>
</div>
<div class="footer">
Web新闻网站
</div>
<script>
let totalHight = document.body.scrollHeight
const Prostick = document.querySelector('.Prostick')
window.addEventListener('scroll', function () {
let pro = (window.pageYOffset / totalhHght) * 100
Prostick.style.width = pro + '%'
})
const navbarRight = document.querySelector('.navbar-right')
const line = document.querySelector('.line')
navbarRight.addEventListener('click',function(e){
if (e.target.tagName === 'A'){
line.style.transform = `translateX(${e.target.tagName}px)`
}
})
document.addEventListener("DOMContentLoaded", function () {
const imgs = [
{ src: "pics/1.png" },
{ src: "pics/2.jpg" },
{ src: "pics/3.jpg" },
{ src: "pics/4.jpg" },
{ src: "pics/5.png" },
];
const carouselImages = document.querySelector('.carousel-images');
const dotsContainer = document.querySelector('.dots-container');
let currentIndex = 0;
imgs.forEach(img => {
const imgElement = document.createElement('img');
imgElement.src = img.src;
carouselImages.appendChild(imgElement);
});
imgs.forEach((_, index) => {
const dot = document.createElement('div');
dot.classList.add('dot');
dot.dataset.index = index;
dotsContainer.appendChild(dot);
});
const dots = document.querySelectorAll('.dot');
function autoPlayCarousel() {
carouselInterval = setInterval(() => {
currentIndex = (currentIndex + 1) % imgs.length;
updateCarousel();
}, 5000);
}
autoPlayCarousel();
document.getElementById('next-btn').addEventListener('click', () => {
currentIndex = (currentIndex + 1) % imgs.length;
updateCarousel();
autoPlayCarousel();
});
document.getElementById('prev-btn').addEventListener('click', () => {
currentIndex = (currentIndex - 1 + imgs.length) % imgs.length;
updateCarousel();
autoPlayCarousel();
});
dots.forEach(dot => {
dot.addEventListener('click', () => {
currentIndex = parseInt(dot.dataset.index);
updateCarousel();
autoPlayCarousel();
});
});
function updateCarousel() {
const offset = -currentIndex * 100 + '%';
carouselImages.style.transform = `translateX(${offset})`;
dots.forEach(dot => dot.classList.remove('active'));
dots[currentIndex].classList.add('active');
}
dots[currentIndex].classList.add('active');
})
const news = document.querySelector('.news-effect')
const navbar = document.querySelector('.navbar')
const carouselContainer = document.querySelector('.carousel-container')
window.addEventListener('scroll', function () {
const n1 = document.documentElement.scrollTop
navbar.style.top = n1 >= news.offsetTop ? 0 : '-65px'
})
const elevator = document.querySelector('.news-elevator')
window.addEventListener('scroll',function(){
const n = document.documentElement.scrollTop
if (n >=300){
elevator.style.opacity = 1
}else{
elevator.style.opacity = 0
}
})
</script>
</body>
</html>