前端知识点

下面是一个最基本的html代码

DOCTYPE html>

<html lang="zh-CN">


<head>
    

    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
    style>
    <script>
        // JavaScript function that displays an alert when called
        function showMessage() {
            alert("Hello! You clicked the button.");
        }
    script>


    <meta charset="UTF-8">
    

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>My First HTML Pagetitle>
    

head>

<body>
    

    <h1>Welcome to My Pageh1>
    

    <p>This is a simple paragraph explaining the content of this page.p>
    

    <a href="https://www.example.com">Visit Example.coma>
    

body>

html>

具体功能的实现

滑动图片的实现

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="description" content="parallax one page" />
    <meta name="keywords" content="technology, optical, silicon, spectrum, application" />

    <!-- Font Google -->
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700,800&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Raleway:400,500,600,700&display=swap" rel="stylesheet">

    <!-- Favicon -->
    <link rel="shortcut icon" href="assets/img/favicon.ico" type="image/x-icon" />
    <link rel="icon" href="assets/img/favicon.ico" type="image/x-icon" />

    <!-- Custom styles (optional) -->
    <link href="assets/css/plugins.css" rel="stylesheet" />
    <link href="assets/css/style.css" rel="stylesheet" />

    <style>
        /* Carousel Container */
        .multi-button-container {
            display: flex;
            overflow-x: auto;
            white-space: nowrap;
            scroll-snap-type: x mandatory;
            gap: 50px;
            padding: 50px;
        }

        /* Carousel Item */
        .multi-button-box {
            flex: 0 0 auto;
            width: 300px;
            height: 400px;
            background-size: cover;
            background-position: center;
            scroll-snap-align: start;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            cursor: pointer;
            color: #FFFFFF;
            text-align: center;
            padding: 20px;
        }

        /* Hide scrollbar */
        .multi-button-container::-webkit-scrollbar {
            display: none;
        }

        /* Display Area for Text */
        .display-area {
            width: 90%;
            margin: 20px auto;
            padding: 20px;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
            display: none;
        }

        /* Display Area Title */
        .display-area h2 {
            margin-top: 0;
        }

        /* Display Area Paragraph */
        .display-area p {
            margin: 10px 0;
        }

        /* Buttons for Scrolling */
        .scroll-button {
            background-color: #2f2e2e;
            color: #ffffff;
            border: none;
            padding: 10px;
            cursor: pointer;
            margin: 10px;
        }
    </style>
</head>

<body class="dsn-effect-scroll dsn-ajax" data-dsn-mousemove="true">

    <main class="main-root">
        <!-- Section for the Image Carousel -->
        <section class="our-work section-margin">
            <div class="container">
                <div class="one-title">
                    <div class="title-sub-container">
                        <p class="title-sub">Applications</p>
                    </div>
                    <h2 class="title-main">应用领域</h2>
                    <!-- Scroll Buttons -->
                    <button class="scroll-button" onclick="scrollContainer(-300)">上一个</button>
                    <button class="scroll-button" onclick="scrollContainer(300)">下一个</button>
                </div>
            </div>

            <!-- Image Carousel -->
            <div class="multi-button-container">
                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('智能穿戴', 'Description for 智能穿戴...')">
                    <h3>智能穿戴</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('化工制药', 'Description for 化工制药...')">
                    <h3>化工制药</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('高端医疗', 'Description for 高端医疗...')">
                    <h3>高端医疗</h3>
                </div>
                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('智能穿戴', 'Description for 智能穿戴...')">
                    <h3>智能穿戴</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('化工制药', 'Description for 化工制药...')">
                    <h3>化工制药</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('高端医疗', 'Description for 高端医疗...')">
                    <h3>高端医疗</h3>
                </div>
                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('智能穿戴', 'Description for 智能穿戴...')">
                    <h3>智能穿戴</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('化工制药', 'Description for 化工制药...')">
                    <h3>化工制药</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('高端医疗', 'Description for 高端医疗...')">
                    <h3>高端医疗</h3>
                </div>


                <!-- Add more boxes as needed -->
            </div>

            <!-- Text Display Area -->
            <div class="container">
                <div id="display-area" class="display-area">
                    <h2 id="display-title"></h2>
                    <p id="display-content"></p>
                </div>
            </div>
        </section>
    </main>

    <!-- Optional JavaScript -->
    <script src="assets/js/jquery-3.1.1.min.js"></script>
    <script src="assets/js/plugins.js"></script>
    <script src="assets/js/dsn-grid.js"></script>
    <script src="assets/js/custom.js"></script>

    <script>
        // Function to display content when an image is clicked
        function showContent(title, content) {
            var displayArea = document.getElementById('display-area');
            document.getElementById('display-title').innerText = title;
            document.getElementById('display-content').innerHTML = content;
            displayArea.style.display = 'block';
        }

        // Function to scroll the image container
        function scrollContainer(distance) {
            document.querySelector('.multi-button-container').scrollBy({ left: distance, behavior: 'smooth' });
        }
    </script>
</body>
</html>

在手机端和电脑端显示不同的图片

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<style> 
    /* Default: Show the desktop image, hide the mobile image */
.desktop-img {
    display: block;
}
.mobile-img {
    display: none;
}
/* When screen width is less than or equal to 768px, show the mobile image, hide the desktop image */
@media (max-width: 1000px) {
    .desktop-img {
        display: none;
    }
    .mobile-img {
        display: block;
    }
}
</style>
</head>
<body>
    <div class="inner-img" data-dsn-grid="move-up">
        <!-- Desktop Image -->
        <img class="desktop-img" src="https://img-home.csdnimg.cn/images/20201124032511.png" alt="">
        <!-- Mobile Image -->
        <img class="mobile-img" src="https://profile-avatar.csdnimg.cn/895333eaf40542089c36e16ba65dce84_qq_41685627.jpg!1" alt="">
    </div>
</body>
</html>

手机端效果
前端知识点_第1张图片
电脑端效果前端知识点_第2张图片

你可能感兴趣的:(前端,javascript,css)