简体   繁体   English

带有模式弹出框的正方形网格

[英]Grid of squares with modal popup

I have coded grid of squares as below: 我已将正方形编码如下:

  <div class='square-container'>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    <div class='square'></div>
    .....

  </div>

I want to add a functionality where when user clicks on any of the squares a nice modal popup will appear. 我想添加一个功能,当用户单击任何正方形时,将出现一个漂亮的模态弹出窗口。 A modal with similar style to this https://codepen.io/khaag/pen/sbcou 具有与此https://codepen.io/khaag/pen/sbcou相似样式的模式

How can achieve something like this with my existing code? 如何用我现有的代码实现类似的目标? Also how make this grid drawing more dynamic than what I have right now? 另外,如何使此网格图形比我现在拥有的更具动态性?

Register an click event as follow: 注册点击事件,如下所示:

$(".square").on("click", function(){
    //////////// Your modal window code
});

Example with tomloprodModal tomloprodModal的示例

$(".square").on("click", function(){
    TomloprodModal.create({
        bgColor: "#FFFFFF",
        textColor: "#333333",
        title: "Hi!", 
        content: "Nothing to say",
    });
});

Updated JSfiddle: https://jsfiddle.net/as1mpe25/2/ 更新了JSfiddle: https ://jsfiddle.net/as1mpe25/2/

include jquery to in your html and add below code 在您的html中包含jQuery并添加以下代码

$(document).ready(function () {

$(".square").click(function(){
    alert("paaoi");/* REPLACE THIS WITH YOUR OWN CODE */
});});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM