jQuery或js点赞功能代码,并且要把数据传到数据库

jQuery或js点赞功能代码,并且要把数据传到数据库,第1张

首先只需要在body中定义一个button。和盛放心的盒子

<div id = "demo"></div>

<input type = "button" id = "btn1" value = "点个赞吧" />

由于还要引进心的图片,所以在这里我们在设置css样式的时候还要设置图片img的样式。

css代码如下:

<style type="text/css">

*{

margin: 0px

padding: 0px

}

#btn1{

position: absolute

bottom:100px

width: 200px

background-color: lightblue

font-size: 18px

left:45%

}

img{

bottom:100px

margin-left: -15px

width: 20px

height:20px

position: absolute

left: 50%

}

</style>

下来就是要写jquery函数。

(document).ready(function(){

// 1. 首先给按钮绑定点击事件。(“#btn1”).click(function(){

//2. 生成彩色的心,即随机选择图片。

// 2.1 生成随机数

var num = Math.floor(Math.random() * 3 +1)

//2.2 生成一个img元素,并为其添加src属性

var image = $(“”)

//三个图片的名字分别是 1.png\2.png\3.png,所以img的路径和图片名可以进行线面的字符串拼接

image.attr(“src”,”./images/”+num+”.png”)

//3。将生成的img追加到页面上

$(“#demo”).append(image)

//4. 下来就是让心动起来。从点击按钮的地方向上飘。利用jquery的动画函数animate()

//生成随机的距离左边的距离,这样就可以使心有种向上飘的感觉

var left = Math.random() * 800

image.animate({

‘bottom':'800px',

‘left':left,

‘opacity':'0'

},3000)

})

});

})

HTML+CSS网站点赞和打赏的功能,实现方法如下:

1、HTML代码:

<body>

<div class="thumbs_content">

    <a href="javascript:void(0)" class="thumbs_button fa fa-thumbs-up" title="点赞,支持一下"> 点赞</a>

    <a href="javascript:void(0)" class="reward_button fa fa-money" title="打赏,支持一下"> 打赏</a>

    <span class="clear"></span>

</div>

</body>

2、CSS代码如下:

<style type="text/css">

.thumbs_content{

    width: 291px

    margin: 0 auto

}

.thumbs_button{

    float: left

    width:145px

    text-align: center

    margin:5px auto

    height: 45px

    line-height: 45px

    background-color:#444

    color:#fbfbfb

    text-align:center

    text-decoration:none

    font-weight:bold

    font-size:16px

    transition: all 0.3s

    border-radius: 0 0 0 25px

    -webkit-border-radius: 0 0 0 25px

    -moz-border-radius: 0 0 0 25px

    -o-border-radius: 0 0 0 25px

}

.reward_button{

    float: left

    width:145px

    text-align: center

    margin:5px auto

    height: 45px

    line-height: 45px

    background-color:#cd4450

    color:#fbfbfb

    text-align:center

    text-decoration:none

    font-weight:bold

    font-size:16px

    border-left:1px solid #fbfbfb

    transition: all 0.3s

    border-radius: 0 25px 0 0

    -webkit-border-radius: 0 25px 0 0

    -moz-border-radius: 0 25px 0 0

    -o-border-radius: 0 25px 0 0

}

.thumbs_button:hover, .reward_button:hover{

    opacity:0.8

    font-size:18px

}

.clear{

    clear:both

</style>

3、效果图:

android点赞功能的数据是通过手机发送请求保存在服务器数据库的。

用户点击点赞图标后会触发一个请求,程序将请求的数据(比如按下为True)发送到服务器,服务器则将数据储存在数据库,下次程序可以直接发送一个请求到服务器获取该用户是否点赞。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9956036.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存