当前位置:网站首页>Interesting research on mouse pointer interaction
Interesting research on mouse pointer interaction
2022-07-03 06:08:00 【xuhss_ com】
High quality resource sharing
Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
---|---|---|
🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |
today , To achieve such an interesting interaction effect :
Change the original mouse pointer style , Modify it to the desired effect , And add some special interaction effects .
Modify mouse style
First , The first question is , We can see , Above picture , The style of the mouse pointer has been changed to a dot :
Normally it should be :
Of course , Here's the easy part , stay CSS in , We can go through cursor
style , Modify the mouse pointer shape .
utilize cursor
Modify mouse style
cursor CSS Property to set the type of mouse pointer , Displays the corresponding style when the mouse pointer hovers over the element .
cursor: auto;
cursor: pointer;
...
cursor: zoom-out;
/* Use pictures */
cursor: url(hand.cur)
/* Use pictures , And set up fallback The bottom line */
cursor: url(hand.cur), pointer;
Everyone should know this , generally , In different scenes , Select different mouse pointer styles , It is also a means to improve the user experience .
Of course , In this interaction , We are not going to cursor Set the cursor to any style , Just the opposite , We need to hide him .
adopt cursor: none
hide cursor
ad locum , We go through cursor: none
Hide the mouse pointer of the page :
{
cursor: none;
}
In this way , The mouse pointer on the page disappears :
Listen through global events , Simulate mouse pointer
since , Vanished , Let's simply simulate a mouse pointer .
We first implement a 10px x 10px
Round div, Set to based on Absolute positioning :
<div id="g-pointer">div>
#g-pointer {
position: absolute;
top: 0;
left: 0;
width: 10px;
height: 10px;
background: #000;
border-radius: 50%;
}
that , On the page , We get a round black spot :
next , Through event monitoring , monitor body Upper mousemove
, The position of the small circle coincides with the position of the real-time mouse pointer :
const element = document.getElementById("g-pointer");
const body = document.querySelector("body");
function setPosition(x, y) {
element.style.transform = `translate(${x}px, ${y}px)`;
}
body.addEventListener('mousemove', (e) => {
window.requestAnimationFrame(function(){
setPosition(e.clientX - 5, e.clientY - 5);
});
});
such , If not set cursor: none
, It will be such an effect :
Give again body add cursor: none
, It is equivalent to simulating a mouse pointer :
On this basis , Due to the current mouse pointer , It's actually a div
, So we can add any interaction effect to it .
Take the example at the beginning of the article , We just need to use the hybrid mode mix-blend-mode: exclusion
, The simulated mouse pointer can intelligently change its own color under different background colors .
There are still questions about the technique of mixed mode , Take a look at my article : Use hybrid mode , Let the text intelligently adapt to the background color
Complete code :
<p>Lorem ipsum dolor sit ametp>
<div id="g-pointer-1">div>
<div id="g-pointer-2">div>
body {
cursor: none;
background-color: #fff;
}
#g-pointer-1,
#g-pointer-2
{
position: absolute;
top: 0;
left: 0;
width: 12px;
height: 12px;
background: #999;
border-radius: 50%;
background-color: #fff;
mix-blend-mode: exclusion;
z-index: 1;
}
#g-pointer-2 {
width: 42px;
height: 42px;
background: #222;
transition: .2s ease-out;
}
const body = document.querySelector("body");
const element = document.getElementById("g-pointer-1");
const element2 = document.getElementById("g-pointer-2");
const halfAlementWidth = element.offsetWidth / 2;
const halfAlementWidth2 = element2.offsetWidth / 2;
function setPosition(x, y) {
element.style.transform = `translate(${x - halfAlementWidth}px, ${y - halfAlementWidth}px)`; element2.style.transform = `translate(${x - halfAlementWidth2}px, ${y - halfAlementWidth2}px)`;
}
body.addEventListener('mousemove', (e) => {
window.requestAnimationFrame(function(){
setPosition(e.clientX, e.clientY);
});
});
We can perfectly restore the effect of the title map :
Complete code , You can poke here :Mouse Cursor Transition
Pseudo class events trigger
One thing to note is that , Use the simulated mouse pointer to Hover Elements ,Click When the elements , You will find that these events cannot be triggered .
This is because , Under the hidden pointer , In fact, we simulate the hovering mouse pointer , therefore , be-all Hover、Click Events are triggered on this element .
Of course , This is also very easy to solve , We just need to give the element that simulates the pointer , add pointer-events: none
, Block default mouse events , Let the event be transmitted through :
{
pointer-events: none;
}
The mouse follow , Not only in the
Of course , The core here is a mouse following animation , Match up cursor: none
.
and , The mouse follow , We don't have to use JavaScript.
I am here It's incredibly pure CSS Mouse following In the article , A kind of pure CSS Achieve the mouse following effect , You can also have a look at those who are interested .
Based on pure CSS Mouse follow for , coordination cursor: none
, You can also make some interesting animation effects . It's like this. :
CodePen Demo – Cancle transition & cursor none
Last
This concludes the article , I hope it helps you
More exciting CSS Technical articles summarized in mine Github – iCSS , Continuous updating , Welcome to point a star Subscribe to the collection .
Any questions or Suggestions , Communicate more , Original article , Writing co., LTD. , Pretty good , If there is anything wrong with the text , All hope to inform .
Want to Get To the most interesting CSS information , Don't miss my iCSS official account :
If you think the article is useful to you , Please feel free to tip . Your support will encourage me to continue to create ! Reward support +## (_) Have a cup of coffee (_)
边栏推荐
- Yum is too slow to bear? That's because you didn't do it
- tabbar的设置
- Download the corresponding version of chromedriver
- There is no one of the necessary magic skills PXE for old drivers to install!!!
- Kubernetes notes (10) kubernetes Monitoring & debugging
- Project summary --2 (basic use of jsup)
- The server data is all gone! Thinking caused by a RAID5 crash
- Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
- Understand one-way hash function
- CAD插件的安裝和自動加載dll、arx
猜你喜欢
Kubesphere - Multi tenant management
Simple solution of small up main lottery in station B
[function explanation (Part 2)] | [function declaration and definition + function recursion] key analysis + code diagram
Tabbar settings
Kubernetes notes (II) pod usage notes
Es remote cluster configuration and cross cluster search
Kubernetes notes (10) kubernetes Monitoring & debugging
Kubernetes notes (VII) kuberetes scheduling
项目总结--2(Jsoup的基本使用)
Jedis source code analysis (II): jediscluster module source code analysis
随机推荐
[teacher Zhao Yuqiang] kubernetes' probe
Analysis of Clickhouse mergetree principle
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
Ext4 vs XFS -- which file system should you use
1. 两数之和
Deep learning, thinking from one dimensional input to multi-dimensional feature input
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
Exportation et importation de tables de bibliothèque avec binaires MySQL
Pytorch builds the simplest version of neural network
[function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation
[teacher Zhao Yuqiang] redis's slow query log
为什么网站打开速度慢?
Beandefinitionregistrypostprocessor
JS implements the problem of closing the current child window and refreshing the parent window
pytorch 搭建神经网络最简版
智牛股项目--05
MySQL带二进制的库表导出导入
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
Simple solution of small up main lottery in station B
Kubernetes cluster environment construction & Deployment dashboard