@@ -67,6 +67,20 @@ const initChat=(root)=>{
6767 const chat_button_img = root . querySelector ( '.maxkb-chat-button > img' )
6868 // 对话框元素
6969 const chat_container = root . querySelector ( '#maxkb-chat-container' )
70+ // 引导层
71+ const mask_content = root . querySelector ( '.maxkb-mask > .maxkb-content' )
72+ const mask_tips = root . querySelector ( '.maxkb-tips' )
73+ chat_button_img . onload = ( event ) => {
74+ if ( mask_content ) {
75+ mask_content . style . width = chat_button_img . width + 'px'
76+ mask_content . style . height = chat_button_img . height + 'px'
77+ if ( '{{x_type}}' == 'left' ) {
78+ mask_tips . style . marginLeft = ( chat_button_img . naturalWidth > 500 ?500 :chat_button_img . naturalWidth ) - 64 + 'px'
79+ } else {
80+ mask_tips . style . marginRight = ( chat_button_img . naturalWidth > 500 ?500 :chat_button_img . naturalWidth ) - 64 + 'px'
81+ }
82+ }
83+ }
7084
7185 const viewport = root . querySelector ( '.maxkb-openviewport' )
7286 const closeviewport = root . querySelector ( '.maxkb-closeviewport' )
@@ -90,17 +104,16 @@ const initChat=(root)=>{
90104 }
91105 const drag = ( e ) => {
92106 if ( [ 'touchmove' , 'touchstart' ] . includes ( e . type ) ) {
93- chat_button . style . top = ( e . touches [ 0 ] . clientY - 25 ) + 'px'
94- chat_button . style . left = ( e . touches [ 0 ] . clientX - 25 ) + 'px'
107+ chat_button . style . top = ( e . touches [ 0 ] . clientY - chat_button_img . naturalHeight / 2 ) + 'px'
108+ chat_button . style . left = ( e . touches [ 0 ] . clientX - chat_button_img . naturalWidth / 2 ) + 'px'
95109 } else {
96- chat_button . style . top = ( e . y - 25 ) + 'px'
97- chat_button . style . left = ( e . x - 25 ) + 'px'
110+ chat_button . style . top = ( e . y - chat_button_img . naturalHeight / 2 ) + 'px'
111+ chat_button . style . left = ( e . x - chat_button_img . naturalWidth / 2 ) + 'px'
98112 }
99113 chat_button . style . width = chat_button_img . naturalWidth + 'px'
100114 chat_button . style . height = chat_button_img . naturalHeight + 'px'
101115 }
102116 if ( { { is_draggable} } ) {
103- console . dir ( chat_button_img )
104117 chat_button . addEventListener ( "drag" , drag )
105118 chat_button . addEventListener ( "dragover" , ( e ) => {
106119 e . preventDefault ( )
@@ -155,7 +168,7 @@ function initMaxkbStyle(root){
155168
156169 #maxkb .maxkb-mask {
157170 position: fixed;
158- z-index: 999 ;
171+ z-index: 10001 ;
159172 background-color: transparent;
160173 height: 100%;
161174 width: 100%;
@@ -242,8 +255,6 @@ function initMaxkbStyle(root){
242255 {{x_type}}: {{x_value}}px;
243256 {{y_type}}: {{y_value}}px;
244257 cursor: pointer;
245- max-height:500px;
246- max-width:500px;
247258 z-index:10000;
248259 }
249260 #maxkb #maxkb-chat-container{
@@ -306,4 +317,4 @@ function embedChatbot() {
306317 initMaxkb ( )
307318 } else console . error ( 'invalid parameter' )
308319}
309- window . onload = embedChatbot
320+ window . addEventListener ( 'load' , embedChatbot )
0 commit comments